Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent nhibernate 如何告诉flunet nhibernate使用基类中的ID(该ID是抽象的,在映射中被忽略)_Fluent Nhibernate_Automapping - Fatal编程技术网

Fluent nhibernate 如何告诉flunet nhibernate使用基类中的ID(该ID是抽象的,在映射中被忽略)

Fluent nhibernate 如何告诉flunet nhibernate使用基类中的ID(该ID是抽象的,在映射中被忽略),fluent-nhibernate,automapping,Fluent Nhibernate,Automapping,我有一个抽象类 public abstract class Document { public int DocumentID {get; set;} } 和派生类 public class DoctorDocument : Document{ public string DoctorName {get;set;} } 我正在使用Fluent自动映射, 我不需要为Document创建一个表,但我需要每个派生类将DocumentID作为主键 mappings.IgnoreBase<D

我有一个抽象类

public abstract class Document
{  
public int DocumentID {get; set;}
}
和派生类

public class DoctorDocument : Document{
public string DoctorName {get;set;}
}
我正在使用Fluent自动映射,
我不需要为Document创建一个表,但我需要每个派生类将DocumentID作为主键

 mappings.IgnoreBase<Document>();
 mappings.AddEntityAssembly(typeof(DoctorDocument).Assembly);
 mappings.Setup(c=>c.FindIdentity = type.Name == type.DeclaringType.Name + "ID";);
mappings.IgnoreBase();
映射.加法汇编(类型(DoctorDocument).汇编);
设置(c=>c.FindIdentity=type.Name==type.DeclaringType.Name+“ID”);
但它仍然找不到ID,并告诉我DoctorDocument没有ID。 但当我进行以下覆盖时,它起了作用:

public class DoctorDocumentMap: IAutoMappingOverride<DoctorDocument>
    {
    public void Override(AutoMapping<DoctorDocument> mapping)
        {
        mapping.Id(x => x.Id, "DocumentID").GeneratedBy.Identity();
        }
}
public类DoctorDocumentMap:IAutoMappingOverride
{
公共无效替代(自动映射)
{
mapping.Id(x=>x.Id,“DocumentID”).GeneratedBy.Identity();
}
}

如何告诉自动映射为所有实体执行此操作??尤其是GeneratedBy.Identity()

覆盖DefaultAutomappingConfiguration可能会有所帮助

类似的方法可能会奏效:

public class MyAppAutoConfiguration : DefaultAutomappingConfiguration
{
    public override bool IsId(Member member)
    {
        return "DocumentID" == member.Name;
    }
}
配置可以如下所示:

 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();
var cfg=新的MyAppAutoConfiguration();
var autoPersistenceModel=AutoMap.AssemblyOf(cfg.IgnoreBase();
ISessionFactory sessionFactory=fluntly.Configure()
.数据库(OracleClientConfiguration)。
Oracle10.ConnectionString(
ConfigurationManager.ConnectionString[“OracleConn”].ConnectionString))
.Mappings(m=>
m、 汽车用品
.Add(自动持久性模型))
.BuildSessionFactory();

谢谢iyad,但我认为DefaultAutomappingConfiguration在新版本1.1中,我使用的是1.0,IsId等于FindIdentity。