Ich habe eine Tabelle mit Produkten und eine weitere Tabelle, die die Produktcodes Produktattributen (eins-zu-viele) mit diesen Modellen zuordnet:
Code: Select all
public class Product
{
public string Code { get; set; }
public string Name { get; set; }
public decimal CatalogPrice { get; set; }
}
public class ProductAttribute
{
public string ProductCode { get; set; }
public string AttributeCode { get; set; } // like "new", "sale", ...
public DateTime ValidFrom { get; set; }
public DateTime ValidTo { get; set; }
}
Code: Select all
public DbSet Products { get; set; }
public DbSet ProductAttributes { get; set; }
Code: Select all
public class Product2
{
public string Code { get; set; }
public string Name { get; set; }
public decimal CatalogPrice { get; set; }
public List? Attributes { get; set; } // the list of attribute codes
}
public DbSet Products2 { get; set; }
Ich habe kein Problem damit, die Seite für die Produkte zu erhalten. Das Problem besteht darin, die Seite zu Products2 zu bekommen – mit der Liste der Attribute für jedes Produkt. Ich weiß nicht, wie ich das machen soll. Ich habe erfolglos gespielt mit...
Code: Select all
DateTime now = DateTime.Now;
var products2 = dbContext.Products
.GroupJoin(dbContext.ProductAttributes,
p => p.Code,
a => a.ProductCode,
(p, a) = new Product2
{
Code = p.Code,
Name = p.Name,
CatalogPrice = p.CatalogPrice,
Attributes = ??? .Where(a => a.ValidFrom
Mobile version