【发布时间】:2023-03-18 01:23:01
【问题描述】:
我有一个类应该使用连接从数据库中获取查询结果。
我的班级是:
`
public class StepTwo
{
public int Id { get; set; }
public string Party { get; set; }
public string Currency { get; set; }
public string Account { get; set; }
public double? Amount { get; set; }
}
`
然后我创建了一个返回结果的方法:
public IEnumerable<StageTwo> StepTwo()
{
var queryJoin = (from inn in db.Input.Take(10)
join yacc in db.AccY on inn.Action equals yacc.Action
orderby inn.Id descending
select new
{
inn.Id,
inn.XParty,
inn.Curr,
yacc.Action,
inn.Amount
});
return queryJoin;
}
在我没有使用连接的其他方法中,这可以正常工作,但现在无法正常工作。我在return queryJoin; 上有错误消息说明:
`
Cannot implicitly convert type 'System.Linq.IQueryable<<anonymous type: int Id, string XParty, string Curr, string YAction, double? Amount>>' to '
System.Collections.Generic.IEnumerable<Project.StepTwo>'. An explicit conversion exists (are you missing a cast?)`
我知道类名与数据库名有些不同,但我已尝试更改它们以匹配。根据上面的错误,我认为它是别的东西。
任何建议将不胜感激,谢谢。
【问题讨论】:
-
为什么选择匿名类而不是
select new StageTwo { Id = inn.Id ... }?
标签: c# entity-framework linq linq-to-sql linq-to-entities