Ich möchte mehrere Dokumente in MongoDB verbinden. Ich habe folgenden Code verwendet, aber es funktioniert nicht. Habe ich irgendwas falsch gedacht? Ich habe das Basiseinheitsmodell hinzugefügt, das die ID enthält.Wie man mehrere Dokumente verbindet?
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();
Bellow ist die Basisentität Ich habe vergessen Basisentität Modell
public class BaseEntity
{
[BsonIgnoreIfDefault]
public ObjectId _id { get; set; }
}
Bellow ist Fehler
Expression des Typs ‚Nachricht hinzufügen System.Collections.Generic.IEnumerable 1[Project.Communication.EntityModels.ProductWarehouseMap]' cannot be used for parameter of type 'System.Linq.IQueryable
1 [Project.Communication.EntityModels.ProductWarehouseMap] 'der Methode' 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]])‘ Parametername: arg0
Wir brauchen mehr als * Erste Fehler *, Ihnen zu helfen, zum Beispiel die Fehlermeldung/den Code. Auch die '_id'-Eigenschaft ist in Ihren Klassendefinitionen nicht zu sehen. –
@KeyurPATEL Plz check obigen Code Ich habe Base-Entity-Modell hinzugefügt, das ID enthält. –
Noch einmal, die Fehlermeldung/Code wäre hilfreich, die '_id' Definition sieht gut aus. –