我有一个功能:
public void Add(User user)
{
var id = WebSecurity.CurrentUserId;
//add id to FK CUserID
context.User.Add(user);
}
我正在将用户数据添加到数据库。如何将 id 值添加到 CUserID?
public class User
{
[key]
public int UserID { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string E-mail { get; set; }
public UserProfile CUserID { get; set; }
}
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int CUserId { get; set; }
public string UserName { get; set; }
}
编辑:如果我尝试这样做:
user.CUserId = id;
我收到一个错误:
无法将类型“int”隐式转换为“Project.Models.UserProfile”