改变用户背景

时间:2013-03-24 23:35:40

标签: c# entity-framework asp.net-mvc-4 ef-migrations

我正在使用MVC4 Internet应用程序,我正在尝试更改帐户模型以使用我的上下文。我似乎无法让它发挥作用。我试图删除上下文并在我的上下文中包含用户配置文件,我可以登录等,但是当我按用户ID检查配置文件时,它返回一个空值。

public DbSet<FightCard> FightCards { get; set; }
public DbSet<Fight> Fights { get; set; }
public DbSet<Fighter> Fighters { get; set; }
public DbSet<UserProfile> UserProfiles { get; set; }

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }

}

当我尝试这样做时:

public ActionResult Profile(int id)
    {
        UserProfile profile = uc.UserProfiles.Find(id);
        ViewBag.Name = profile.UserName;
    }

我得到一个null值返回。任何人都知道如何使用不同的上下文成功使用简单成员资格吗?

1 个答案:

答案 0 :(得分:1)

在那里解决了。但说实话,我不确定是什么解决了它。这是我使用的链接,其中一部分解决了我的问题。

http://dansgreenshoes.com/2013/03/10/mvc4usertable/

相关问题