鉴于有多个重复栏用于审计和版面的数据库,使用NHibernate的最佳方式是不必重复本领域每一类的栏目?
数据库的每个表格都重复了这9个栏目,名称和类型是相同的,我不想在域模型中复制。
我阅读了该书,我看到了关于遗产规划的章节,但我看不出如何在这一设想中发挥作用。 这似乎是一种共同的设想,因为几乎每个数据库都有四个共同审计栏(CreatedBy, CreatDate, UpdatedBy, UpdateDate)。 这个数据库没有变化,只是引入每个表格共有的另外五个栏目。
鉴于有多个重复栏用于审计和版面的数据库,使用NHibernate的最佳方式是不必重复本领域每一类的栏目?
数据库的每个表格都重复了这9个栏目,名称和类型是相同的,我不想在域模型中复制。
我阅读了该书,我看到了关于遗产规划的章节,但我看不出如何在这一设想中发挥作用。 这似乎是一种共同的设想,因为几乎每个数据库都有四个共同审计栏(CreatedBy, CreatDate, UpdatedBy, UpdateDate)。 这个数据库没有变化,只是引入每个表格共有的另外五个栏目。
可以通过在绘图档案中使用构成部分来做到这一点。
基本想法是设立一个类别,以掌握共同财产,并在你的模式中从每个实体那里查阅。
然后,在您的地图档案中添加提及此类财产的内容。
<component name="RecordMetadata" class="RecordMetadata" insert="true" update="true">
<property name="UpdatedBy" />
<property name="UpdatedDate" />
<property name="CreatedBy" />
<property name="CreatedDate" />
</component>
http://fluentnhibernate.org/“rel=“nofollow noreferer”>Fluent NHibernate,以创建你的绘图档案。 这使你能够利用你的绘图档案继承遗产。 例如:
public class AuditableClassMap<T> : ClassMap<T> where T : IAuditable
{
public AuditableClassMap()
{
Map(x => x.CreatedBy);
Map(x => x.CreatedDate, "CreatedDt");
Map(x => x.RevisedBy);
Map(x => x.RevisedDate, "RevisedDt");
}
}
public class CompanyMap : AuditableClassMap<Company>
{
// mapping for Company
}
借助编号4的代号,你应当能够撰写一份单一的代号文件,该代号为:.hbm.xml
文档,其所有类别都有界定。 我设想如下。 首先,在<代码>.tt的延伸中编造一个文档,并在以下代码中:
<#@ template language="C#v3.5" #>
<#@ output extension="hbm.xml" #>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MyNameSpace">
<#
System.Collections.Generic.Dictionary<string, string> classes = new System.Collections.Generic.Dictionary<string, string>();
classes.add("RootNameSpace.SubNameSpace.MyClass1", "Table1");
foreach(string className in classes.keys)
{
#>
<class name="<#=className#>, AssemblyName" table="<#=classes[className]#>">
<id name="ID" column="EntityID" type="Int32">
<generator class="native" />
</id>
<property name="Property1" />
<property name="Property2" />
</class>
<#
}
#>
</hibernate-mapping>
最后一个步骤是将产出文件编成“建设行动”,以吸收资源,而且你应当做得好。
You can read more about t4 code generation here: http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx
http://code.google.com/p/codeconform/“rel=“nofollow noretinger”>ConfORM。
在许多情况下,它将做你的工作all。 如果是这样的话,就很容易界定你们的公约和凌驾一切。
Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...
Given the following Fluent NHibernate maps: public class FastTrackPackageClassMap : ClassMap<FastTrackPackage> { public FastTrackPackageClassMap() { Id(x => x.Id); ...
I had a scenario in Oracle where i need to match a substring part of column with a list of values. i was using sqlfunction projection for applying the substring on the required column, and added that ...
I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...
I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...
I have two associated business objects - A and B. the association is (A->B)many-to-one, with B.Id a foreign key in A (so A has A.B_id in the DB). I m using lazy=true and solved most of my problems, ...
Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...
I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....