我有一个包含一些属性的类。由于某些架构原因,我的班级中有另一个对象的实例。
简单的例子
public class MyEntity {
public MySubEntity SubEntity {get; set;}
}
为此,我创建了流畅的映射,例如:
builder.ToTable(MyEntity.CONST_TABLE_NAME);
builder.HasKey(m => m.Id);
builder.Property(m => m.Column1).IsRequired();
builder.Property(m => m.SubEntity.Column2).IsRequired();
我无法将所有 subEntity 属性集成到我的主实体中(我的 subEntity 有自己的智能)。我只想将未存储在单独表中的子实体属性映射到 myEntity 表。
最后一行抛出异常:
The expression 'm => m.SubEntity.Column2' is not a valid property expression. The expression should represent a property access: 't => t.MyProperty'.
我怎样才能执行这样的映射?