我正试图像这样设置一个变量......
var userID = WebMatrix.WebData.WebSecurity.CurrentUserId;
var options = db.UserProfiles.Find(userID).TaskTypeSetting;
我正在使用基本Internet应用程序模板提供的用户身份验证表。
表UserId
中的行UserProfile
与表User
中的行TaskTypeSetting
具有一对多关系。
它告诉我它无法找到TaskTypeSetting
的定义。如果我的关系设置得当,我不应该这样做吗?
以下是该表的模型:
namespace DailyTaskList.Models
{
using System;
using System.Collections.Generic;
public partial class TaskTypeSetting
{
public int ID { get; set; }
public int Type { get; set; }
public int User { get; set; }
}
}
看起来它没有将关系添加到代码中? .edmx图显示了我设置的关系。
修改
UserProfile类定义:
namespace DailyTaskList.Models
{
using System;
using System.Collections.Generic;
public partial class UserProfile
{
public int UserId { get; set; }
public string UserName { get; set; }
}
}
编译器错误消息: CS1061:'DailyTaskList.Models.UserProfile'不包含'TaskSetting'的定义,也没有扩展方法'TaskSetting'接受'DailyTaskList.Models类型的第一个参数。可以找到UserProfile'(您是否缺少using指令或程序集引用?)
我也是在映射详细信息下得到这个:
Mappings are not allowed for an association over exposed foreign keys.
答案 0 :(得分:1)
经过一些研究,我发现我遇到的是Visual Studio 2012和Entity Framework的错误。实体框架未能正确生成我的代码。这是由于.edmx文件嵌套在项目文件中引起的。
我使用的解决方案:
其他解决方案:
我写了一篇关于情况的博客,可以找到here。