0
我有以下类别:许多使用EF 4.1代码第一个设计
public class CartItem
{
public long Id { get; set; }
public int Quantity { get; set; }
public Product Product { get; set; }
}
public class Product {
public long Id { get; set; }
public string Title { get; set; }
public decimal Price { get; set; }
}
目前,我有以下配置:
modelBuilder.Entity<CartItem>().HasRequired(x => x.Product).WithMany().Map(x => x.MapKey("ProductId"));
我想确保每当我检索cartitem从数据库中将会有一个产品表上的连接,所以我可以访问产品属性,但不能以其他方式访问。
我基本上要能够做到:使用配置我
string title = cartItem.Product.Title
让我不设置到对象异常的实例的对象引用。