Asp.net 实体框架上下文正在选择查询中添加无效列

Asp.net 实体框架上下文正在选择查询中添加无效列,asp.net,c#-4.0,entity-framework-4,Asp.net,C# 4.0,Entity Framework 4,以下是我的类属性: public int ProductId { get; set; } public string Name { get; set; } public DateTime Creation { get; set; } public int BrandId { get; set; } public virtual Brand Brand { get; set; } public int CreatedBy { get; set; }

以下是我的类属性:

    public int ProductId { get; set; }
    public string Name { get; set; }
    public DateTime Creation { get; set; }
    public int BrandId { get; set; }
    public virtual Brand Brand { get; set; }
    public int CreatedBy { get; set; }
    public decimal Price { get; set;         
    public string Description { get; set; }
    public string Properties { get; set; }
    public bool OnFrontPage { get; set; }
    public int StockCount { get; set; }
    public decimal MarketPrice { get; set; }
    public int CurrencyId { get; set; }
    public virtual Currency Currency { get; set; }
    public int TaxRate { get; set; }
    public bool IsNewProduct { get; set; }
    public bool IsActive { get; set; }
    public string MetaDescription { get; set; }
    public string MetaKeyWord { get; set; }
    public int UnitId { get; set; }
    public virtual Unit Unit { get; set; }
    public int PointValue { get; set; }
    public string RelatedProductIds { get; set; }
    public int MaxSaleCount { get; set; }
    public int ProductGroupId { get; set; }
    public virtual ProductGroup ProductGroup { get; set; }
    public virtual List<ProductCategory> ProductCategories { get; set; }
    public virtual List<ProductType> ProductTypes { get; set; }
    public virtual List<ProductImage> ProductImages { get; set; }
    public virtual List<Promotion> Promotions { get; set; }
    public int SaleCount { get; set; }
    public virtual List<ProductChance> ProductChances { get; set; }
    public string ProductCode { get; set; }
类别:

public int CategoryId { get; set; }

public string Name { get; set; }
public string LinkText { get; set; }
public int? ParentId { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public bool IsActive { get; set; }
public virtual List<Product> Products { get; set; }
public DateTime Creation { get; set; }
public int CreatedBy { get; set; }
public bool IsParentCategory { get; set; }
public int CategoryId{get;set;}
公共字符串名称{get;set;}
公共字符串LinkText{get;set;}
公共整数?ParentId{get;set;}
公共字符串说明{get;set;}
公共字符串ImageUrl{get;set;}
公共bool IsActive{get;set;}
公共虚拟列表产品{get;set;}
公共日期时间创建{get;set;}
public int CreatedBy{get;set;}
公共bool IsParentCategory{get;set;}

好吧,您可能将该关系设置为一对多(或者,当您拥有另一个实体的IList时,EF完成了该操作,但另一部分没有任何内容,我必须承认我不知道这一点)

无论如何,这并不是因为您不想在产品类中看到导航属性“Category”,数据库不需要FK来保持这两个实体之间的关系

数据库的需求与其对象的对应项不同

其他示例:如果您创建多对多关系

public class A {
public virtual IList<B> Bs {get;set;}
}

public class B {
 public virtual IList<A> As {get;set;}
}
公共A类{
公共虚拟IList Bs{get;set;}
}
公共B级{
公共虚拟IList为{get;set;}
}

EF将创建一个表a、表B和表AB。但在对象世界中,AB表不是作为实体(不需要)出现的。

能否显示类别类?是否先使用代码?如果是这样的话,那可能是因为你建立了这种关系。
public class A {
public virtual IList<B> Bs {get;set;}
}

public class B {
 public virtual IList<A> As {get;set;}
}