Methods 访问dbset子类型上的扩展方法
我有一个扩展方法定义为:Methods 访问dbset子类型上的扩展方法,methods,dbset,Methods,Dbset,我有一个扩展方法定义为: public static class CurrentItemExtensions { static GPOPricingEntities ctx = new GPOPricingEntities(); public static List<CurrentItem> Get(this DbSet<CurrentItem> item, int tierId, string contractId) { Lis
public static class CurrentItemExtensions
{
static GPOPricingEntities ctx = new GPOPricingEntities();
public static List<CurrentItem> Get(this DbSet<CurrentItem> item, int tierId, string contractId)
{
List<CurrentItem> items = ctx.Items.OfType<CurrentItem>().Where(x => x.TierId == tierId).ToList();
if (items == null)
{
GPOPricing.AS400Models.ItemCollection collection = new GPOPricing.AS400Models.ItemCollection().Get(contractId);
foreach (var c in collection)
{
CurrentItem target = new CurrentItem();
target.Price = c.DirectPriceEaches;
target.SKU = c.LongItemNbr;
target.Description = c.Description;
target.ProductLine = c.ProductLine;
items.Add(target);
}
}
else
{
foreach (var i in items)
{
GPOPricing.AS400Models.Item as400Item = new GPOPricing.AS400Models.ItemCollection().GetBySKU(i.SKU);
i.Description = as400Item.Description;
i.ProductLine = as400Item.ProductLine;
}
}
return items;
}
}
我已经试过了
db.Items.OfType<CurrentItem>().Get (doesn't work)
db.Items.OfType().Get(不工作)
有什么建议吗?我发现我必须使用基类型并为每个子类型创建一个方法:
public static class CurrentItemExtensions
{
static GPOPricingEntities ctx = new GPOPricingEntities();
public static List<CurrentItem> GetCurrentItems(this DbSet<Item> item, int tierId, string contractId)
{
List<CurrentItem> items = ctx.Items.OfType<CurrentItem>().Where(x => x.TierId == tierId).ToList();
if (items.Count() == 0)
{
GPOPricing.AS400Models.ItemCollection collection = new GPOPricing.AS400Models.ItemCollection().Get(contractId);
foreach (var c in collection)
{
CurrentItem target = new CurrentItem();
target.Price = c.DirectPriceEaches;
target.SKU = c.LongItemNbr;
items.Add(target);
}
}
else
{
foreach (var i in items)
{
GPOPricing.AS400Models.Item as400Item = new GPOPricing.AS400Models.ItemCollection().GetBySKU(i.SKU);
}
}
return items;
}
}
公共静态类CurrentItemExtensions
{
静态GPOPricingEntities ctx=新的GPOPricingEntities();
公共静态列表GetCurrentItems(此DbSet项,int tierId,字符串压缩)
{
List items=ctx.items.OfType()。其中(x=>x.TierId==TierId.ToList();
如果(items.Count()==0)
{
GPOPricing.AS400Models.ItemCollection collection=新的GPOPricing.AS400Models.ItemCollection().Get(construcd);
foreach(集合中的var c)
{
CurrentItem目标=新的CurrentItem();
target.Price=c.DirectPriceEaches;
target.SKU=c.LongItemNbr;
增加(目标);
}
}
其他的
{
foreach(项目中的var i)
{
GPOPricing.AS400Models.Item as400Item=新的GPOPricing.AS400Models.ItemCollection().GetBySKU(i.SKU);
}
}
退货项目;
}
}
public static class CurrentItemExtensions
{
static GPOPricingEntities ctx = new GPOPricingEntities();
public static List<CurrentItem> GetCurrentItems(this DbSet<Item> item, int tierId, string contractId)
{
List<CurrentItem> items = ctx.Items.OfType<CurrentItem>().Where(x => x.TierId == tierId).ToList();
if (items.Count() == 0)
{
GPOPricing.AS400Models.ItemCollection collection = new GPOPricing.AS400Models.ItemCollection().Get(contractId);
foreach (var c in collection)
{
CurrentItem target = new CurrentItem();
target.Price = c.DirectPriceEaches;
target.SKU = c.LongItemNbr;
items.Add(target);
}
}
else
{
foreach (var i in items)
{
GPOPricing.AS400Models.Item as400Item = new GPOPricing.AS400Models.ItemCollection().GetBySKU(i.SKU);
}
}
return items;
}
}