我是 MVC 的新手,我只是想建立一个简单的网站。我首先使用 EF 代码。我的问题是 MVC 总是为我不想要永久存储的模型寻找数据库表,(当我使用它时,我只会初始化它的一个对象)这是我的代码:
public class Family
{
public int FamilyId { get; set; }
public String FamilyName { get; set; }
public String FamilyJoinString { get; set; }
public String MemberIds { get; set; }
public virtual List<FamilyMember> Members { get; set; }
public List<FamilyMember> GetFamilyMembers()
{
var db = new HomeTrackerDb();
var CommonHelper = new CommonHelper();
var members = new List<FamilyMember>();
var memberids = MemberIds;
var ids = CommonHelper.SplitToList(memberids, ",");
foreach (var id in ids)
{
var user = db.UserInfoes.Find(int.Parse(id));
var member = new FamilyMember();
member.FamilyMemberId = user.UserInfoId;
member.FamilyMemberName = user.UserName;
member.FamilyMemberLoad = 0;
members.Add(member);
}
db.Dispose();
return members;
}
}
//FamilyMember Class
public class FamilyMember
{
public int FamilyMemberId { get; set; }
public String FamilyMemberName { get; set; }
public int FamilyMemberLoad { get; set; }
}
}
我只在控制器中生成 FamilyMember 列表,没有数据库更新、插入和查找操作。控制器:
public ActionResult Edit(int id)
{
Family family = db.Families.Find(id);
family.Members = family.GetFamilyMembers();
return View(family);
}
但是 MVC 总是说找不到数据库表 FamilyMembers。
请帮忙!