linq2sql:使用 ExceuteQuery当返回的行不在我的 dto 中时?我可以使用通用数据类型吗?
一直在使用 ExecuteQuery 并取得了一些成功,即 AccessRights 是我的 dto 并且 queryString 包含“Exec sp_name param1,param2 等”
var accessRights =
this.db.ExecuteQuery<AccessRights>(queryString, sqlParams.Values.ToArray()).AsQueryable();
如果从存储过程返回的内容可以完美映射到我在泛型中传递的类型(dto),那么一切都很完美ExecuteQuery
问题现在是我有一个返回非标准列名的存储过程。
基本上我的 AccessRights 类(dto)包含“userId”、“accessRightId”、“Description”,
但新的存储过程返回 UserId、AccessRightId、“TemporaryDescription”。
现在我无法更改它,因为其他事情取决于它......如果我这样做,
var accessRights =
this.db.ExecuteQuery<AccessRights>(queryString, sqlParams.Values.ToArray()).AsQueryable();
我就看不到“TemporaryDescription”,我认为这是合乎逻辑的,因为它不存在
我需要做的是将temporaryDescription映射回描述。
任何人都知道如何做到这一点?
been using ExecuteQuery with some success, i.e. where AccessRights is my dto and queryString contains "Exec sp_name param1,param2 etc"
var accessRights =
this.db.ExecuteQuery<AccessRights>(queryString, sqlParams.Values.ToArray()).AsQueryable();
Everything works perfect if what returns from the stored procedure can be mapped perfectly to the type (dto) that i pass in the generic ExecuteQuery
Problem is now i have a stored procedure that returns a non standard column name.
Basically my i hav my AccessRights class (dto) which contains, "userId", "accessRightId", "Description"
but the new stored procedure returns UserId, AccessRightId, "TemporaryDescription".
now i can't change it as other things depend on it... if I do
var accessRights =
this.db.ExecuteQuery<AccessRights>(queryString, sqlParams.Values.ToArray()).AsQueryable();
then i don't see "TemporaryDescription", which i suppose is logical as it doesn't exist
What i need to do is map temporaryDescription back to description.
Any body has any idea how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试添加
[Column(...)]
属性;不知道这是否有效。脑海中浮现出几个选项:
Select
或 LINQ 查询)在您的实际预期类中You could try adding the
[Column(...)]
attribute; no idea if that'll work.A few options that leap to mind:
Select
, or a LINQ query) into your actual intended class