开发者

how to tell flunet-nhibernate to use the ID from a base class (which is abstract and ignored in the mapping)

i have an abstract class

public abstract class Document
{  
public int DocumentID {get; set;}
}

and derived class

public class DoctorDocument : Document{
public string DoctorName {get;set;}
}

and I'm using Fluent Auto Mapping,

i need not to make a table for Document, but i need each derived class to get the DocumentID as Primary Key.

 mappings.IgnoreBase<Document>();
 mappings.AddEntityAssembly(typeof(DoctorDocument).Assembly);
 mappings.Setup(c=>c.FindIdentity = type.Name == type.DeclaringType.Name + "ID";);

but it still can't find the ID and tells me that DoctorDocument doesn't have an ID. but when i made the following override it worked:

public class DoctorDocumentMap: IAutoMappingOverride<DoctorDocument>
    {
    public void Override(AutoMapping<Doctor开发者_StackOverflowDocument> mapping)
        {
        mapping.Id(x => x.Id, "DocumentID").GeneratedBy.Identity();
        }
}

how can i tell the automapping to do that for all entities?? especially the GeneratedBy.Identity();


Overriding DefaultAutomappingConfiguration might help.

Something like this might work :

public class MyAppAutoConfiguration : DefaultAutomappingConfiguration
{
    public override bool IsId(Member member)
    {
        return "DocumentID" == member.Name;
    }
}

The configuration can be like this:

 var cfg = new MyAppAutoConfiguration();
        var autoPersistenceModel = AutoMap.AssemblyOf<Person>(cfg).IgnoreBase<Document>();
        ISessionFactory sessionFactory = Fluently.Configure()
            .Database(OracleClientConfiguration.
            Oracle10.ConnectionString(
                ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString))
             .Mappings(m =>
                m.AutoMappings
                  .Add(autoPersistenceModel))
              .BuildSessionFactory();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜