【发布时间】:2011-12-16 13:56:52
【问题描述】:
我正在使用 EF4 检索数据库对象。我已经定义了一个总结用户信息的视图。
在 SSMS 中,我使用 select * 或存储过程得到 8 个不同的结果。
示例:
在 EF4 中查询时,我的视图返回 8 个结果,但属性 UserTeamName 始终作为第一个值 (BoboTeam) 返回。这很奇怪,因为UserRole 被正确返回,这些项目之间的区别在于UserTeamName 可以为空。
这似乎是 EF 的问题,因为对象是由来自 System.Data.Objects.ObjectContext 的 ExecuteFunction 方法填充的:
public ObjectResult<MySecurityView> SecurityList(Nullable<global::System.Int32> userId)
{
ObjectParameter userIdParameter;
if (userId.HasValue)
{
userIdParameter = new ObjectParameter("userId", userId);
}
else
{
userIdParameter = new ObjectParameter("userId", typeof(global::System.Int32));
}
return base.ExecuteFunction<MySecurityView>("SecurityList", userIdParameter);
}
当我们使用 linqtosql 请求而不是存储过程时,结果相同。欢迎任何提示。
【问题讨论】:
标签: sql-server-2008 entity-framework stored-procedures view