public class User
{
public Account Account { get; set; }
public string SomeInfo { get; set; }
public Guid Id { get; set; }
}
public class Account
{
public string Name { get; set; }
}
public class UserEntityTypeConfiguration : IEntityTypeConfiguration<User>
{
public virtual void Configure(EntityTypeBuilder<User> builder)
{
builder.HasKey(x => x.Id);
builder
.Property(t => t.Id)
.ValueGeneratedOnAdd();
}
}
我可以映射到一个看起来像这样的表吗?
| Id | SomeInfo | AccountName |
-------------------------------
| 1 | info1 | name1 |
| 2 | info2 | NULL |
在映射之后, 1 将映射到:
User.SomeInfo is "info1"
User.Account is not null
User.Account.Name is "name1"
加载 2 会导致
User.SomeInfo is "info2"
User.Account is null
任何人都可以帮忙吗?