EFCore добавление свойств тени по умолчанию - PullRequest
0 голосов
/ 05 января 2019

Я использую EFCore (с Cosmos), и по какой-то причине он добавляет для меня 2-й ключ, по условию id, несмотря на то, что у него есть имя свойства Id, с KeyAttribute.

В любом случае, я могу это остановить?

    public class User
    {

    public User()
    {

    }
    public User(ClaimsPrincipal principal)
    {
        Id = principal.FindFirst(ClaimTypes.NameIdentifier).Value;
        FirstName = principal.FindFirst(ClaimTypes.GivenName).Value;
        Surname = principal.FindFirst(ClaimTypes.Surname).Value;
        Email = principal.FindFirst(ClaimTypes.Email).Value;
    }

    [Key]

    public string Id { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public bool Active { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime LastLoginTime { get; set; }

    public Company Company { get; set; }

    public User CreatedBy { get; set; }

    //Hack to get around EF/Cosmos Enum error
    private string UserType { get; set;}

    [NotMapped]
    public UserType UserTypeEnum
    {
        get
        {
            if (string.IsNullOrWhiteSpace(UserType))
            {
                return Models.UserType.User;
            }
            return (UserType)Enum.Parse(typeof(UserType), UserType);
        }
        set
        {
            UserType = value.ToString();
        }
    }
}

Added Shadow Property

1 Ответ

0 голосов
/ 05 января 2019

Вы можете добавить [Newtonsoft.Json.JsonProperty(PropertyName="id")] над своим идентификатором

Ссылка

...