该类型不能被隐式转换为系统。到system.collections.generic.list< crypto>
public async Task<List<Crypto>> GetWithoutPrices()
{
List<Crypto> cryptos = await _context.cryptocurrencies.Select(c => new
{
name = c.Name,
id = c.Id,
UpdateDate = c.updateDate
}).ToListAsync();
return cryptos;
}
public class Crypto
{
public int Id { get; set; }
public decimal Price { get; set; }
public string Name { get; set; }
public DateTime updateDate { get; set; }
}
错误信息:
类型不能隐式转换为“ system.collections.generic.list&lt;&lt;匿名类型:字符串名称,int id,system.dateTime intement.datetime更新&gt;&gt;”到“ system.collections.generic.list&lt; cryptoapi.modules
public async Task<List<Crypto>> GetWithoutPrices()
{
List<Crypto> cryptos = await _context.cryptocurrencies.Select(c => new
{
name = c.Name,
id = c.Id,
UpdateDate = c.updateDate
}).ToListAsync();
return cryptos;
}
public class Crypto
{
public int Id { get; set; }
public decimal Price { get; set; }
public string Name { get; set; }
public DateTime updateDate { get; set; }
}
Error message:
The type cannot be converted implicitly "System.Collections.Generic.List<<anonymous type: string name, int id, System.DateTime UpdateDate>>" to "System.Collections.Generic.List<CryptoAPI.Modules
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您目前正在返回作为匿名类型的列表。
相反,指定
.select()
的类型,并建议使用 pascalcase (公共)属性的命名。
You are currently returning as a List of anonymous type.
Instead, specify the type in
.Select()
And would suggest using PascalCase naming for (public) properties.