在这种情况下,数据过滤仅支持基本类型或枚举类型

时间:2018-07-19 10:08:54

标签: c#

我在说System.NotSupportedException: 'Unable to create a constant value of type 'ZikFunnelItemUpdate_Console.Models.Item'. Only primitive types or enumeration types are supported in this context.'

时出错

也请在图片中检查deleteList, updateList, addList是否工作正常,但在deleteImageList上使用相同的代码,因为我使用实体实体db.ItemGalleries从数据库中获取数据并从数据库中查找数据,但出现以下错误。我的问题您知道解决此问题的任何快速解决方案吗?请问您是否有疑问。请注意:Item和ItemGallery ItemID是链接的主键

pic

主要代码:

var EixistingItems = db.Items.Where(x => x.UserStoresID == uStore.UserStoresID).ToList();

                    var addList = new List<Item>();
                    var updateList = new List<Item>();
                    var deleteList = new List<Item>();
                    var deleteImageList = new List<ItemGallery>();

                    deleteList = EixistingItems.Where(ei => !MyItemList.Any(ni => ni.EbayID == ei.EbayID)).ToList();
                    updateList = EixistingItems.Where(ei => MyItemList.Any(ni => ni.EbayID == ei.EbayID)).ToList();
                    addList = MyItemList.Where(ni => !EixistingItems.Any(ei => ei.EbayID == ni.EbayID)).ToList();


                    deleteImageList = db.ItemGalleries.Where(ei => deleteList.Any(ni => ni.ItemID == ei.ItemID)).ToList();

2 个答案:

答案 0 :(得分:0)

您可以在where语句之后使用select语句

deleteImageList = db.ItemGalleries.Select(x=> new ItemGallery{/*Select Items*/}).Where(ei => deleteList.Any(ni => ni.ItemID == ei.ItemID)).Select(x=> new ItemGallery{/*Select Items*/}).ToList();

答案 1 :(得分:0)

您可以从ItemID中找到deleteList的列表,并按如下所示检查.Contains

deleteListIds = deleteList.Select(ni => ni.ItemID).ToList();
deleteImageList = db.ItemGalleries.Where(ei => deleteListIds.Contains(ei.ItemID)).ToList();