In Entity Framework 4, I'm facing a problem when I use function import to a stored procedure and then using as a scalar value. It generates the code below:
public virtual ObjectResult<Nullable<int>> GetTopEmployee()
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>("GetTopEmployee");
}
How do I use the return value of this method?
For example, this code works fine:
NorthwindEntities db = new NorthwindEntities();
var i = db.GetTopEmployee();
But I want to use return values only as int. If I use return value as non while in function import it give -1 as output.
When I try the code below:
NorthwindEntities db2 = new NorthwindEntities();
int j = db.GetTopEmployee();
It throws an error saying:
Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'int'
How do I parse the above?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…