2
これは以前に尋ねられている必要がありますが、私はそれを検索する良い方法を見つけることができませんでした。ef cf linqは無視されたプロパティを埋め込みます
私はここ
public class VendorConfiguration : EntityTypeConfiguration<Vendor>
{
public VendorConfiguration()
{
Property(p => p.Name).IsRequired().HasMaxLength(128);
Ignore(v => v.ProductCount);
}
}
のようなコンフィギュレーションクラスの設定は、私はベンダーをつかむために使用するクエリである必要があり、次の
public class Vendor
{
public int VendorId { get; set; }
public string Name { get; set; }
public int ProductCount { get; set; }
}
のようなクラスを持っています。
public Vendor[] GetVendors()
{
using (var db = new UbidContext())
{
var query = (from vendor in db.Vendors
select vendor);
return query.ToArray();
}
}
は、どのように私は私がメインクエリにそれを追加することができます方法はあり
ProductCount = (from vend in db.VendorProducts
where vend.VendorId == id
select vend).Count()
のようになりサブクエリでProductCountを読み込むことができたので、私は唯一の1つの呼び出しを作ってるんですDB?
おかげで、 アンドリュー
ありがとうございました:)それはまさに私が探していたものです。 – no1ross