小编no1*_*oss的帖子

ef cf linq populate ignored property

我确定之前已经问过这个问题,但我找不到一个好的方法来搜索它.

我有一个类似以下的课程

public class Vendor
{
    public int VendorId { get; set; }
    public string Name { get; set; }
    public int ProductCount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我有一个配置类设置

public class VendorConfiguration : EntityTypeConfiguration<Vendor>
{
    public VendorConfiguration()
    {
        Property(p => p.Name).IsRequired().HasMaxLength(128);
        Ignore(v => v.ProductCount);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我用来抓住供应商的查询.

    public Vendor[] GetVendors()
    {
        using (var db = new UbidContext())
        {
            var query = (from vendor in db.Vendors
                                        select vendor);

            return query.ToArray();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我怎么能用一个看起来类似的子查询填充ProductCount

ProductCount = (from vend in db.VendorProducts
 where vend.VendorId …
Run Code Online (Sandbox Code Playgroud)

linq entity-framework ef-code-first c#-4.0

2
推荐指数
1
解决办法
349
查看次数

标签 统计

c#-4.0 ×1

ef-code-first ×1

entity-framework ×1

linq ×1