是的,你可以做到這一點用流利的API下面是一個例子:
public class User
{
public int UserId { get; set; }
public Address Address { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }
public Address Address { get; set; }
}
[ComplexType]
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
public class Context : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Customer> Customers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().Property(u => u.Address.Street)
.HasColumnName("UserStreet");
modelBuilder.Entity<Customer>().Property(u => u.Address.Street)
.HasColumnName("CustomerStreet");
}
}
不要使用CTP5。安裝稱爲4.1 RC的新版本 - http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2dc5ddac-5a96-48b2-878d-b9f49d87569a&displaylang=en – 2011-03-16 08:11:14
我認爲CTP5是「最終」?新版本是否解決了這個問題? – 2011-03-16 15:57:56
不,CTP從未被認爲是最終版本。也就是說,EF 4.1 RC似乎是比CTP5更重要的bug修復版本。 – 2011-03-16 18:42:17