L2实体,存储过程和映射 [英] L2Entities, stored procedure and mapping

查看:57
本文介绍了L2实体,存储过程和映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后检查了L2E框架,几乎立即遇到了问题.
是的,我知道...我应该先读书.

Finally checked out L2E framework and ran into problems almost instantly.
Yeah, i know... i should read some books before.

情况:

带有道具的实体-> ID和名称.
实体映射到具有id和name列的表.
sproc,仅返回id列.

entity with props -> id and name.
entity is mapped to table, which has id and name columns.
sproc, which returns ONLY id column.

问题:

ObjectResult<MyProp> result = _container.MyStoredProcedure(uberParameter);

调用此方法会导致错误

[有罪的方法在这里]引发了异常: System.Data.EntityCommandExecutionException:数据读取器与指定的'DataBase.MyPropTableObject'不兼容.类型名称"的成员在数据读取器中没有具有相同名称的对应列.

[guilty method goes here] threw exception: System.Data.EntityCommandExecutionException: The data reader is incompatible with the specified 'DataBase.MyPropTableObject'. A member of the type, 'name', does not have a corresponding column in the data reader with the same name..

问题2:

不能仅返回"该字段,导致该列具有XML数据类型,但是sproc使用奇特的select语句,这会导致:

Can`t "just return" that field, cause that column has XML data type, but sproc uses fancy select statements, which causes:

第421条消息,状态16,状态1,第1行 无法将xml数据类型选择为DISTINCT,因为它不可比较.

Msg 421, Level 16, State 1, Line 1 The xml data type cannot be selected as DISTINCT because it is not comparable.

问题:
是否有可能仅为此一个程序专门为此实体道具关闭映射?

Question:
Is it possible to exclusively turn off mapping for this entity prop only for this one sproc?

推荐答案

问题1是由于proc没有用于填充实体的列所致.如果您已映射了表,则实际上并不需要proc,只需使用linq从表中选择所需的字段即可.

Problem 1 is due to the proc not having the columns to populate the entity. You don't really need the proc if you have mapped the table, just select the field you want from it using linq

var result = MyEntities.EntityIMapped.First(r => r.id = uberParameter).Name;

将从表的名称"列为您提供给定ID的值.您无需为此使用存储的proc.

Would give you the value from the Name column of the table for the given id. You don't need to use a stored proc for this.

问题2听起来像是在proc中,我认为xml数据列上的不同会带来很多结果,但是我只是在猜测,因为我不知道您的解决方案.

Problem 2 sounds like it is in the proc, I would think that distinct on an xml data column would give a lot of results, but I'm only guessing as I don't know your solution.

这不是您问题的直接答案,但希望它将为您指明正确的方向.

This is not a direct answer for your question but, hopefully it will point you in the right direction.

这篇关于L2实体,存储过程和映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆