无法在LINQ to> Entities查询中构造实体或复杂类型'ChildAccessory'

我想我理解以下错误,但不确定如何解决,

  

“ Classname”:“ System.NotSupportedException”,“ Message”:“实体或   复杂类型'Childaccessory'不能在LINQ中构造为   实体查询。”,

我应该创建一个DTO并将其从存储库中返回以解决该问题,还是有更好的解决方法?

我正在尝试获取儿童配件,但还包括父表中的默认配件。

public class ChildaccessoryRepository: IChildaccessoryRepository {
 private readonly EquipmentContext _context;

 public DirectoryEquipmentRepository(EquipmentContext context) {
  _context = context;
 }

 public IEnumerable < Childaccessory > getchildaccessories(Guid clientReference) {
  var accessories = from a in _context.accessory
  join ca in _context.Childaccessory
  on new {
   accessoryId = a.Id,ClientReference = clientReference
  }
  equals new {
   ca.accessoryId,ca.ClientReference
  }
  into ca_join
  from ca in ca_join.DefaultIfEmpty()
  where
  ca.Isactive == true ||
   ca.Isactive == null
  //select ca;
                         select new Childaccessory
                                   {
                                       accessoryId = ca.accessoryId,SomeOtherColumn = ca.SomeOtherColumn,accessory = ca.accessory,});

 }
}
yyb4051 回答:无法在LINQ to> Entities查询中构造实体或复杂类型'ChildAccessory'

ChildAccessory是否有无参数的构造函数?

本文链接:https://www.f2er.com/3125385.html

大家都在问