如何调用存储过程与空间返回列 [英] How to call stored procedure that returns columns with spaces

查看:94
本文介绍了如何调用存储过程与空间返回列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打电话给使用单位6.0的存储过程。希望这些解决方案后,<一个href=\"http://www.entityframeworktutorial.net/$c$c-first/column-dataannotations-attribute-in-$c$c-first.aspx\"相对=nofollow>这里和<一个href=\"http://stackoverflow.com/questions/10077865/how-to-create-complex-datatype-for-column-with-spaces-in-the-name/10080489#10080489\">here,他们并没有解决问题。问题是返回一列中有一个空间(我无法更改存储过程)。我曾尝试没有成功如下:

I'm trying to call a stored procedure using entity 6.0. After looking to these solutions here and here, they didn't solve the problem. The issue is that one of the returned columns has a spaces in it (I'm unable to change the stored procedure). I've have tried the following with no success:

MyModel.cs

MyModel.cs

using System;
...

namespace ...
{
    public class MyModel
    {
        [Display(Name = "ID")]
        public string id{ get; set; }

        [Display(Name = "Number Of ID")]
        [Column("Number Of ID")]
        public int number_Of_ID { get; set; }

    }

    public class MyModelContext : DbContext
    {
        public DbSet<MyModel> MyModels{ get; set; }
    }
}

MyController.cs

MyController.cs

using System;
...

namespace ...
{
    public class MyController : Controller
    {
        private MyEntities db = new MyEntities ();

        public ActionResult Index()
        {

            var query = @"exec usp_getIds";

            var results = db.Database.SqlQuery<MyModel>(query);
            return View(results);
        }
    }

在调试code,我的模型有 ID 而不是 number_Of_ID 的值。该值始终为0。我也试图改变数据类型为字符串并返回。请帮助。

When debugging the code, my model has a value for id but not for number_Of_ID. The value is always 0. I've also tried changing the datatype to a string and it returns null. Please help.

推荐答案

你的意思是有空格的列名或一个值?

Do you mean there are spaces in a column name or in a value?

有关存储过程usp_getIds,你应该能够做到:

For a stored procedure usp_getIds, you should be able to do:

List<usp_getIds_Result> results = db.usp_getIds().ToList();

当您添加程序到模型的

usp_getIds_Result 自动创建。

The class usp_getIds_Result is automatically created when you add the procedure to the model.

看它是否有助于试试这个。

See if it helps to try this.

这篇关于如何调用存储过程与空间返回列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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