在数据读取错误的实体框架 [英] Error in data reader in entity framework
本文介绍了在数据读取错误的实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在执行这个简单的查询与实体框架
I'm executing this simple query with Entity Framework
db.Database.SqlQuery<string>("SELECT * FROM hospital");
不过,我得到这个错误:
But I got this error:
数据读取器有一个以上的域。多领域不适用于电火花加工的原始或枚举类型。
The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types.
这可能是什么问题?
推荐答案
这将看到什么医院表看起来像,但假设一些简单的像医院由HospitalId和HospitalName,那么你有一对夫妇的选择是有用的。
It would be useful to see what the hospital table looks like but assuming something simple like hospital consists of HospitalId and HospitalName then you have a couple of choices.
db.Database.SqlQuery<IEnumerable<string>>("SELECT hospitalName FROM hospital"); //would work if all you're trying to do is get the Name
db.Database.SqlQuery<MyEntity>("SELECT * FROM hospital"); //where you define MyEntity as the same structure as the table would work
db.Database.SqlQuery<IEnumerable<Tuple<int, string>>>("SELECT * FROM hospital"); // would theoretically work although I haven't tried it. Where the Tuple items would have to match the database types in order. I.e. if field 1 is an int and field 2 is a string then Tuple<int,string>
基本上错误是code不知道如何东西院的结构转换为字符串
Basically the error is the code doesn't know how to stuff the structure of hospital into a string
这篇关于在数据读取错误的实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文