Asp.net core mvc enntity框架核心两个独立于数据库实体的数据列表

Asp.net core mvc enntity框架核心两个独立于数据库实体的数据列表,asp.net-core-mvc,entity-framework-core,Asp.net Core Mvc,Entity Framework Core,我的控制器中有两个列表(.net core mvc 2.0,使用实体框架核心访问数据库) 两者都是数据库中的品牌列表 在品牌中,我有colum徽标,其中包含徽标名称,仅用于为客户端创建完整路径,我将路径附加数据 homeData.NewBrands.ForEach(x => x.BrandLogo = BrandLogo + "/" + x.BrandLogo); homeData.ListBrands.ForEach(x => x.BrandLogo = BrandLogo +

我的控制器中有两个列表(.net core mvc 2.0,使用实体框架核心访问数据库)

两者都是数据库中的品牌列表 在品牌中,我有colum徽标,其中包含徽标名称,仅用于为客户端创建完整路径,我将路径附加数据

 homeData.NewBrands.ForEach(x => x.BrandLogo = BrandLogo + "/" + x.BrandLogo);
 homeData.ListBrands.ForEach(x => x.BrandLogo = BrandLogo + "/" + x.BrandLogo);
若同一品牌出现在两个列表中,那个么追加url将重复,因为它们代表相同的对象

http://localhost:4399/Uploads/BrandLogo/http://localhost:4399/Uploads/BrandLogo/IMKbershkaD_19_Mar_2018_13_10_10.png
我尝试了新的内部选择

  homeData.NewBrands=_context.Brands.OrderByDescending(x => x.CreationDate).Select(x=>new Brand() {BrandCoverImages=x.BrandCoverImages,BrandDEscriptionAr=x.BrandDEscriptionAr,BrandDEscriptionEn=x.BrandDEscriptionEn,BrandID=x.BrandID,BrandLocations=x.BrandLocations,BrandLogo=x.BrandLogo }).Take(5).ToListAsync();
它对我来说很有用,但我甚至必须对brandCover图像这样的内部对象使用new,因为我还必须更改内部对象中的路径。从数据库中选择时,是否有其他方法创建新对象。我正在使用entity core 2.0进行数据访问

您需要的是。无跟踪意味着EF(1)不会跟踪上下文中返回的实体实例,(2)不会重用上下文已跟踪的实体实例。有关更多详细信息,请参阅

话虽如此,只需向查询根添加
AsNoTracking()

homeData.ListBrands = await _context.Brands.AsNoTracking().Where(...
homeData.NewBrands = await _context.Brands.AsNoTracking().OrderByDescending(...
homeData.ListBrands = await _context.Brands.AsNoTracking().Where(...
homeData.NewBrands = await _context.Brands.AsNoTracking().OrderByDescending(...