数据读取器与指定的字段不兼容

时间:2014-12-08 13:53:54

标签: c# asp.net asp.net-mvc

我正在尝试显示两个表中的一些数据:Category和Transactions。 我的错误是:

An exception of type 'System.Data.EntityCommandExecutionException' occurred in System.Data.Entity.dll but was not handled in user code

Additional information: The data reader is incompatible with the specified 'GestaoFinanceiraModel.Category'. A member of the type, 'id_Category', does not have a corresponding column in the data reader with the same name.

我的代码就是这样:

var dbCategories = db.Category.SqlQuery("select Cat.name, isnull(Tr.Soma, 0) from Category cat left join (select category, sum(amout) as soma from Transactions where month(date)='11' group by category) tr ON cat.id_Category=Tr.category order by cat.name").ToList();

当我在sql server上运行这个sql语句时,返回:

id_Category is_active   name    budget  is_budget_active    alert
1   1   testeCat    0   0   1
2   1   teste2  0   0   1
3   1   teste3  0   0   1
4   1   teste4  0   0   1
5   1   teste5  0   0   1

为什么会发生这种情况?

0 个答案:

没有答案