/Xtensive.Storage/Xtensive.Storage/Attributes/HierarchyRootAttribute.cs

https://code.google.com/p/dataobjectsdotnet/ · C# · 82 lines · 21 code · 7 blank · 54 comment · 0 complexity · 3eba3aa5cfc3fe878360a085654a2712 MD5 · raw file

  1. // Copyright (C) 2003-2010 Xtensive LLC.
  2. // All rights reserved.
  3. // For conditions of distribution and use, see license.
  4. // Created by: Dmitri Maximov
  5. // Created: 2008.01.11
  6. using System;
  7. using Xtensive.Core.Internals.DocTemplates;
  8. using Xtensive.Storage.Model;
  9. namespace Xtensive.Storage
  10. {
  11. /// <summary>
  12. /// Defines root type of hierarchy of persistent types.
  13. /// </summary>
  14. /// <remarks>
  15. /// <para>
  16. /// All entities in your model can be divided into one or more persistent hierarchies.
  17. /// Persistent hierarchy is a set of entities, that are inherited from one entity class(hierarchy root)
  18. /// and have the same key structure. Hierarchy root entity should be marked by this attribute.
  19. /// </para>
  20. /// <para>
  21. /// Persistent hierarchies can use diffirent inheritance schemas, e.g. all instances of hierarchy can be
  22. /// stored in a single table or different tables should be crated for each entity class. Inheritance schema
  23. /// can be specified in <see cref="InheritanceSchema"/> property.
  24. /// </para>
  25. /// </remarks>
  26. /// <example>In following example two persistent type hierarchies are declared.
  27. /// Inheritance shema is specified for documents hierarchy.
  28. /// <code>
  29. /// [HerarchyRoot]
  30. /// public class Product : Entity { ... }
  31. ///
  32. /// [HerarchyRoot(InheritanceSchema = InheritaceSchema.ClassTable)
  33. /// public class Document : Entity { ... }
  34. ///
  35. /// public class Invoice : Document { ... }
  36. /// </code>
  37. /// </example>
  38. [Serializable]
  39. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
  40. public sealed class HierarchyRootAttribute : StorageAttribute
  41. {
  42. /// <summary>
  43. /// Gets the inheritance schema for this hierarchy.
  44. /// </summary>
  45. /// <remarks>
  46. /// Persistent hierarchies can use diffirent inheritance schemas, e.g. all instances of hierarchy can be
  47. /// stored in a single table or different tables should be crated for each entity class.
  48. /// </remarks>
  49. public InheritanceSchema InheritanceSchema { get; set; }
  50. /// <summary>
  51. /// Gets or sets a value indicating whether key should include TypeId field.
  52. /// </summary>
  53. /// <remarks>
  54. /// TypeId can be included into entity Key for some specific optimization purposes.
  55. /// Default value is <see langword="false" />.
  56. /// </remarks>
  57. public bool IncludeTypeId { get; set; }
  58. // Constructors
  59. /// <summary>
  60. /// <see cref="ClassDocTemplate.Ctor" copy="true"/>
  61. /// </summary>
  62. public HierarchyRootAttribute()
  63. : this(InheritanceSchema.Default)
  64. {
  65. }
  66. /// <summary>
  67. /// <see cref="ClassDocTemplate.Ctor" copy="true"/>
  68. /// </summary>
  69. /// <param name="schema">The inheritance schema for the hierarchy.</param>
  70. public HierarchyRootAttribute(InheritanceSchema schema)
  71. {
  72. InheritanceSchema = schema;
  73. }
  74. }
  75. }