Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework Can';t获取实体框架中的存储过程以返回值_Entity Framework_Stored Procedures_Ef Code First_Entity Framework 6 - Fatal编程技术网

Entity framework Can';t获取实体框架中的存储过程以返回值

Entity framework Can';t获取实体框架中的存储过程以返回值,entity-framework,stored-procedures,ef-code-first,entity-framework-6,Entity Framework,Stored Procedures,Ef Code First,Entity Framework 6,我尝试在数据库中创建一个存储过程,并在SQLServerManagementStudio中对其进行了测试(效果很好),但当我使用实体框架从MVC应用程序调用它时,当我展开“结果”视图时,结果显示“无法评估子对象” 这是我到目前为止所做的尝试 public void ExecuteStoredProcedure() { //var gift = context.Gifts.SqlQuery("dbo.GetGiftsFromId @p0", 1); var

我尝试在数据库中创建一个存储过程,并在SQLServerManagementStudio中对其进行了测试(效果很好),但当我使用实体框架从MVC应用程序调用它时,当我展开“结果”视图时,结果显示“无法评估子对象”

这是我到目前为止所做的尝试

public void ExecuteStoredProcedure()
    {
        //var gift = context.Gifts.SqlQuery("dbo.GetGiftsFromId @p0", 1);

        var result = context.Database.SqlQuery<Gift>("dbo.GetGiftsFromId @p0", 1);

    }
有人知道为什么电话没有回音吗?我在其他帖子中看到一些人在代码中使用modelbinder.Entity等。我需要这样做吗

我首先使用代码,这是我的礼物对象

public class Gift
{
    // for a one-to-one relationship
    // great tutorial on code-first
    //http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx

    public Gift()
    {
        Images = new List<GiftImage>();
    }

    public int GiftId { get; set; }

    public DateTime DateCreated { get; set; } 

    [Required]
    public string Name { get; set; }

    public virtual ICollection<GiftCategory> Categories { get; set; }

    public int Rating { get; set; }

    public GiftStatus Status { get; set; }

    [Required]
    public int OwnerId { get; set; }

    [Required]
    public virtual GiftAddress GiftAddress { get; set; }

    public GiftAvailability Availability { get; set; }

    [Required]
    public virtual GiftDescription Description { get; set; }

    public byte[] Thumbnail { get; set; }

    [Required]
    public virtual ICollection<GiftImage> Images { get; set; }

    public ICollection<GiftReview> Reviews { get; set; }
}
公共类礼品
{
//一对一的关系
//关于代码优先的伟大教程
//http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx
公共礼物()
{
图像=新列表();
}
公共int GiftId{get;set;}
public DateTime DateCreated{get;set;}
[必需]
公共字符串名称{get;set;}
公共虚拟ICollection类别{get;set;}
公共整数评级{get;set;}
公共礼品状态{get;set;}
[必需]
public int OwnerId{get;set;}
[必需]
公共虚拟礼品服饰礼品服饰{get;set;}
公共礼品可用性{get;set;}
[必需]
公共虚拟礼物描述描述{get;set;}
公共字节[]缩略图{get;set;}
[必需]
公共虚拟ICollection映像{get;set;}
公共ICollection审阅{get;set;}
}
我必须使用

results.ToList()
为了得到结果


或者获取结果并对其进行处理。

我甚至编写了一些ado.net代码以使sp运行,并且运行良好,我可以从sp返回数据。这里的问题是EF,我不确定是否在某个地方缺少一些代码。注意:我直接在数据库中创建了存储过程。我在创建SP时没有使用任何类型的代码优先方法。这有关系吗?
results.ToList()