문제

I have a model

public class BaseCave

    public string OldSasaCode { get; set; }
    [Display(Name = "Cave Name")]
    public string Name { get; set; }
    public string Description { get; set; }
    public double Longitude { get; set; }
    public double Latitude { get; set; }
    public DateTime LastEditDate { get; set; }
    public ApplicationUser LastEditMember { get; set; }
    public bool IsDeleted {get; set;}
}

public class Cave: BaseCave
{
    public int CaveID { get; set; }
}

and i use this on ApplicationDbContext created by ASP.NET-Identiy. I set the LastEditMember property equals to the current logged in member and save.

In the DB the last editmember's ID is Saved in my Cave table, but when i load the Cave entity, the LastEditMember property is null, eventhough the ID for the user was sucsesfully saved in the DB.

도움이 되었습니까?

해결책

any Related Entities must be marked as virtual for entity framework to be able to use them.

This also indicates to Entity Framework that it is a related Entity.

So in this example it should have been:

public virtual ApplicationUser LastEditMember { get; set; }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top