如何将存储过程结果映射到自定义类?

2024-05-16

我在用entity framework 5我已经添加了两个存储过程到我的.edmx model.

第一个存储过程返回一个字符串,如果我在 Visual Studio 中打开模型浏览器,我可以更改Returns a Collection Of节并将标量类型设置为 String,如下所示:

然后在代码中,我可以调用 SP 并得到如下结果:

using (var context = new MyEntities())
{
    var spResult = context.mySPNameFromTheModel(exampleParameter1, exampleParameter2); // This will get the output as string
}

上面的示例工作正常,但是如何对 Complex 类型执行相同的操作?

My second stored procedure returns just one row, with two columns, both strings. So I created a class with two string properties, but I cannot see it when I change to Complex, I cannot select anything from the drop down because it is empty. ComplexType

当我点击Get Column Information,它只是说 SP 不返回任何列,这是不正确的。


  • 检查edmx是否用相应的存储过程更新
  • 尝试在模型浏览器中手动创建复杂类型。
  • 保存并重建解决方案
  • 然后尝试添加函数导入并给函数 importname, sp & 在返回集合中选择手动创建的复杂类型。
  • 现在单击获取列信息。
  • 然后单击“确定”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将存储过程结果映射到自定义类? 的相关文章

随机推荐