我配置了两张桌子'级联关系,即HasOne'。 当我尝试更新和查询时,它没问题,但是当我尝试为数据库创建一个新实体时,除了foreignkey列之外,所有数据都已正确创建。
public class Customer
{
public string Id { get; set; }
public string Name { get; set; }
public string Age { get; set; }
public string Mark { get; set; }
public CustomerInfo Detail { get; set; }
}
public class CustomerInfo
{
public string Id { get; set; }
public string Info { get; set; }
public string CustomerId { get; set; }
}
public class CustomerMap : ClassMap<Customer>
{
public CustomerMap()
{
Table("[dbo].[Customer]");
Not.LazyLoad();
Id(t => t.Id).GeneratedBy.UuidHex("D");
Map(t => t.Name);
Map(t => t.Age);
Map(t => t.Mark);
HasOne(t =>t.Detail).PropertyRef(t=>t.CustomerId).Not.LazyLoad().Cascade.All();
}
}
public class CustomerInfoMap : ClassMap<CustomerInfo>
{
public CustomerInfoMap()
{
Table("[dbo].[CustomerInfo]");
Not.LazyLoad();
Id(t => t.Id).GeneratedBy.UuidHex("D");
Map(t => t.Info);
Map(t => t.CustomerId);
}
}