我想加入MongoDB中的多个文档。我使用了下面的代码,但它不起作用。我做错了吗?我添加了包含Id的基本实体模型。如何加入多个文件?
var products = _productRepository.GetCollection(_dbContext);
var prodWarhoseMapping = _productWarehouseMapRepository.GetCollection(_dbContext);
var warhouses = _warehouseRepository.GetCollection(_dbContext);
public class Product:BaseEntity
{
public string product_code { get; set; }
public decimal fat_tax { get; set; }
}
public class ProductWarehouseMap :BaseEntity
{
public ObjectId product_id { get; set; }
public ObjectId warehouse_id { get; set; }
public int qty { get; set; }
public decimal price { get; set; }
}
public class Warehouse :BaseEntity
{
public ObjectId supplier_id { get; set; }
public string warehouse_code { get; set; }
public string name { get; set; }
public string email { get; set; }
public string phone { get; set; }
public string street_address { get; set; }
public string city { get; set; }
public string postal_code { get; set; }
public string region { get; set; }
public string country { get; set; }
public string manager_name { get; set; }
public string fax { get; set; }
}
//works proper
var query1 = (from p in products
join pm in prodWarhoseMapping on p._id equals pm.product_id
select new
{
Products = p,
ProductMapping = pm,
}).ToList();
//Getting error
var query = (from p in products
join pm in prodWarhoseMapping on p._id equals pm.product_id
join wh in warhouses on pm.warehouse_id equals wh._id
select new
{
Products = p,
ProductMapping = pm,
Warehouse = wh
}).ToList();
娄是基本实体 我忘了添加碱实体模型
public class BaseEntity
{
[BsonIgnoreIfDefault]
public ObjectId _id { get; set; }
}
娄是错误消息
类型的“表达System.Collections.Generic.IEnumerable 1[Project.Communication.EntityModels.ProductWarehouseMap]' cannot be used for parameter of type 'System.Linq.IQueryable
1 [Project.Communication.EntityModels.ProductWarehouseMap]'of method'System.Linq.IQueryable 1[Project.Communication.EntityModels.ProductWarehouseMap] Where[ProductWarehouseMap](System.Linq.IQueryable
1 [Projec t.Communication.EntityModels.ProductWarehouseMap],System.Linq.Expressions.Expression 1[System.Func
2 Project.Communication.EntityModels.ProductWarehouseMap,System.Boolean])” 参数名:为arg0
我们需要比*获取错误的详细*帮助你,例如错误消息/代码。另外'_id'属性无处可见你的类定义。 –
@KeyurPATEL Plz检查上面的代码我已经添加了包含id的基本实体模型。 –
再一次,错误消息/代码会很有帮助,'_id'定义看起来不错。 –