我有实体:
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
...
public virtual Profile Profile { get; set; }
...
public class Profile
{
public int UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
当我尝试获取用户时出现错误:
System.Data.Edm.EdmEntityType: : EntityType 'Profile' has no key defined. Define the key for this EntityType.
当我将实体更改为:
public class User
{
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
...
public virtual Profile Profile { get; set; }
...
public class Profile
{
[Key]
public int UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
我得到错误:
{"Invalid column name 'Profile_UserId'."}
我究竟做错了什么?