1

Possible Duplicate:
Get values in NotMapped property in model class Entity Framwork Code First using linq

I am using Entity Framework 5's Code First in my project and my model looks more or less like this:

public class Category
{
    public int CategoryId { get; set; }
    public string Name { get; set; }

    public virtual Category Parent { get; set; }

    [NotMapped]
    public int Level { get; set; }
}

The generated table contains all columns except the Level column (as expected)

Now, I have a stored procedure which calculates the Level of the Category node in relation to it's parent.

If I execute the stored procedure in SQL Server Mgmt Studio it returns the columns as specified in my model including the [NotMapped] Level column.

The thing is: the Level column is not filled if I call the stored procedure like this: Context.Database.SqlQuery<TModel>(storedProcedure, parameterArray); where TModel is Category.

Is there any way to 're-use' this Category model?

4

1 回答 1

0

您清楚地说属性“Level”不是您模型的一部分,因此它当然不会被您的存储过程填充。为什么你会期待别的?

唯一的方法是手动解析 sp 的结果并自己创建模型类的实例。

于 2013-01-02T21:06:53.200 回答