实体框架函数导入问题
我正在使用 Entity Framework 4.0 和 POCO。我从数据库添加一些实体,然后重命名实体属性。 例如,我有表“Person”,其中包含字段ID,Name。我将我的实体重命名为“Person”:
ID-> PR_ID,
名称 -> PR_名称。
然后我创建存储过程:
select * from Person
然后我基于此 sp 创建函数导入,并指定实体“Person”作为返回类型。 当此函数导入在运行时发生时,我得到异常:
{"The data reader is incompatible with the specified 'Model.Person'.
A member of the type, 'PR_ID', does not have a corresponding column
in the data reader with the same name."}
这是我的问题:
- 如果存在“Person”实体的映射,它会告诉将 ID 转换为 PR_ID 和 < strong>将Name转换为PR_Name,为什么我的函数导入不使用这个映射?
- 我可以为 sp 中的每一列指定别名,例如:
从 Person 选择 ID 作为 PR_ID,名称作为 PR_Name
但还有其他解决方案吗?
谢谢你!
I am using Entity Framework 4.0 with POCO. I add some entities from database, then i rename entity properties.
For example i have table "Person" with fields ID, Name. I rename my entity "Person" so:
ID -> PR_ID,
Name -> PR_Name.
Then i create stored procedure:
select * from Person
Then i create function import based on this sp, and specify Entity "Person" as return type.
When this function import occurs at run-time i get exception:
{"The data reader is incompatible with the specified 'Model.Person'.
A member of the type, 'PR_ID', does not have a corresponding column
in the data reader with the same name."}
here is my questions:
- If there is mapping for "Person" entity, which tells convert ID to PR_ID and convert Name to PR_Name, why my function import doesn`t use this mapping?
- I can specify aliases for each column in sp, like:
select ID as PR_ID, Name as PR_Name from Person
but is there other solution?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在存储过程中指定列名称。如果不这样做,函数导入就无法推断映射。
You need to specify the column names in the stored procedure. If you don't there is no way for the function import to infer the mapping.