Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#linq填充非映射属性_C#_Entity Framework_Linq To Sql - Fatal编程技术网

c#linq填充非映射属性

c#linq填充非映射属性,c#,entity-framework,linq-to-sql,C#,Entity Framework,Linq To Sql,我首先使用实体框架代码,我有两个实体: public class Product { public int ProductID { get; set; } public decimal Price { get; set; } public int ProductCategoryID { get; set; } public virtual ProductCategory ProductCategory { get; set; } [NotMa

我首先使用实体框架代码,我有两个实体:

public class Product 
{
    public int ProductID { get; set; }     
    public decimal Price { get; set; }
    public int ProductCategoryID { get; set; }
    public virtual ProductCategory ProductCategory { get; set; }

    [NotMapped]
    public int Quantity { get; set; }
} 

public class ProductStorage
{
  [Key]
  public int ProductId { get; set; }


  [ForeignKey("ProductId")]
  public virtual Product Product { get; set; }

  public int Quantity { get; set; }

}
我似乎无法获得填充有
数量属性的
产品
列表

我试过了

from pr in repository.Query<Product>()
   join st in repository.Query<ProductStorage>() on pr.ProductID equals st.Quantity
   select new Product()
   {
       ProductID = pr.ProductID,
        ....
       Quantity = st.Quantity

   };
来自repository.Query()中的pr
pr.ProductID上的join st in repository.Query()等于st.Quantity
选择新产品()
{
ProductID=pr.ProductID,
....
数量=标准数量
};

但是这不起作用。

您的
加入
错误的字段上完成
,请尝试以下操作:

from pr in repository.Query<Product>()
join st in repository.Query<ProductStorage>() on pr.ProductID equals st.ProductID 
select new Product()
   {
   ProductID = pr.ProductID,
        ....
   Quantity = st.Quantity
   };
public class Product 
{
    public int ProductID { get; set; }     
    public decimal Price { get; set; }
    public int ProductCategoryID { get; set; }
    public virtual ProductCategory ProductCategory { get; set; }
    public virtual ProductStorage Storage { get; set; }

    [NotMapped]
    public int Quantity { get { return this.Storage.Quantity; }  }
}