C# 自动印刷机投掷';序列不包含任何元素';(无效操作例外)
我试图使用AutoMapper将一个实体列表直接从一个C# 自动印刷机投掷';序列不包含任何元素';(无效操作例外),c#,asp.net-mvc,entity-framework,asp.net-web-api,automapper,C#,Asp.net Mvc,Entity Framework,Asp.net Web Api,Automapper,我试图使用AutoMapper将一个实体列表直接从一个IQueryable投射到一个dto,但是它似乎总是失败,出现一个InvalidOperationException声明序列不包含任何元素 实体 public class GatewaySetup { public static Expression<Func<GatewaySetup, ICollection<Parameter>> ParametersAccessor = gatew
IQueryable
投射到一个dto,但是它似乎总是失败,出现一个InvalidOperationException
声明序列不包含任何元素
实体
public class GatewaySetup {
public static Expression<Func<GatewaySetup, ICollection<Parameter>>
ParametersAccessor = gateway => gateway.ParametersStorage;
protected virtual ICollection<Parameter> ParametersStorage { get; set; }
public int Id { get; protected set; }
public IEnumerable<Parameter> Parameters {
get { return ParametersStorage.AsEnumerable(); } // linq2entities
}
}
公共类网关设置{
公共静态表达式网关。参数存储;
受保护的虚拟ICollection参数存储{get;set;}
public int Id{get;protected set;}
公共IEnumerable参数{
获取{return ParametersStorage.AsEnumerable();}//linq2entities
}
}
DTO
public class GatewaySetupDto {
public int Id { get; set; }
public List<ParameterDto> Parameters { get; set; }
}
公共类网关设置到{
公共int Id{get;set;}
公共列表参数{get;set;}
}
映射
Mapper.CreateMap<GatewaySetup, GatewaySetupDto>()
.ForMember(x => x.Parameters, options =>
options.MapFrom(GatewaySetup.ParametersAccessor));
Mapper.CreateMap()
.ForMember(x=>x.参数,选项=>
options.MapFrom(GatewaySetup.ParametersAccessor));
Api
return _repository.Project().To<GatewaySetupDto>();
return_repository.Project().To();
这可能是什么原因?AutoMapper在IEnumerable
和列表之间的映射失败吗?原因是:或者可能是此处解释的另一个方向:此外,您是否有参数到/参数的映射?原因是:或者可能是此处解释的另一个方向:也,您是否有参数
/参数到
的映射?因此:或者这里可能解释的另一个方向:您是否有参数
/参数到
的映射?