views:

29

answers:

1

hi every one,
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<DoctorDocument> 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();

+1  A: 

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();
Iyad
Thank you iyad,but i figured that DefaultAutomappingConfiguration is in the new version 1.1and I'm using 1.0and IsId is equal to FindIdentity.
Nour Sabouny

related questions