以下是生成的模型:
public class DbObjectMap : EntityTypeConfiguration<DbObject>
{
public DbObjectMap()
{
// Primary Key
HasKey(t => new { t.Type, CompanyName = t.CompanyName, Id = t.Id });
// Properties
Property(t => t.Timestamp)
.IsRequired()
.IsFixedLength()
.HasMaxLength(8)
.IsRowVersion();
Property(t => t.Type)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.CompanyName)
.IsRequired()
.HasMaxLength(30);
this.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
this.Property(t => t.Name)
.IsRequired()
.HasMaxLength(30);
this.Property(t => t.VersionList)
.IsRequired()
.HasMaxLength(80);
this.Property(t => t.LockedBy)
.IsRequired()
.HasMaxLength(132);
// Table & Column Mappings
this.ToTable("Object");
this.Property(t => t.Timestamp).HasColumnName("timestamp");
this.Property(t => t.Type).HasColumnName("Type");
this.Property(t => t.CompanyName).HasColumnName("Company Name");
this.Property(t => t.Id).HasColumnName("ID");
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.Modified).HasColumnName("Modified");
this.Property(t => t.Compiled).HasColumnName("Compiled");
this.Property(t => t.BlobReference).HasColumnName("BLOB Reference");
this.Property(t => t.BlobSize).HasColumnName("BLOB Size");
this.Property(t => t.DbmTableNo).HasColumnName("DBM Table No_");
this.Property(t => t.Date).HasColumnName("Date");
this.Property(t => t.Time).HasColumnName("Time");
this.Property(t => t.VersionList).HasColumnName("Version List");
this.Property(t => t.Locked).HasColumnName("Locked");
this.Property(t => t.LockedBy).HasColumnName("Locked By");
}
}
和:
{
public ObjectTrackingMap()
{
// Primary Key
HasKey(t => new { ObjectType = t.ObjectType, Id = t.Id, ChangeType = t.ChangeType });
// Properties
Property(t => t.Timestamp)
.IsRequired()
.IsFixedLength()
.HasMaxLength(8)
.IsRowVersion();
Property(t => t.ObjectType)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.ChangeType)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
// Table & Column Mappings
ToTable("Object Tracking");
Property(t => t.Timestamp).HasColumnName("timestamp");
Property(t => t.ObjectType).HasColumnName("Object Type");
Property(t => t.Id).HasColumnName("Object ID");
Property(t => t.ChangeType).HasColumnName("Change Type");
Property(t => t.ObjectTimestamp).HasColumnName("Object Timestamp");
}
}
这两个对象在数据库表中没有任何关系。但它们可以通过
Object.Type = ObjectTracking.ObjectType
和Object.ID = ObjectTracking.ObjectID
字段连接。
有什么方法可以在 EF 中使用 FluentAPI 为这两个实体创建正确的映射?