Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Trouble with CF entityframework migration (Principal Ends)

$
0
0

Hi,
In my scenario, I am trying to apply CF EF migration to create my tables in DB from entities. The following error shows up when I run add-migration.

Unable to determine the principal end of an association between the types 'MarvelManager.API.Models.Entities.MemberImage' and 'MarvelManager.API.Models.Entities.Member'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

My entity classes are as follows. Initially, in the line where virtual ApplicationUser was declared it had ForeignKey as marker attrib. I removed that and instead applied Required attrib. But no. That did not do the trick. Should I try the same in the MemberImage class and apply Required over the Member property? I do not want to randomly apply things without realizing this first. ApplicationUser is pretty straight forward, as you can see below.  LogChange is just a base class that is used to record/register created edited updated date times, respective user ids etc. 

public class Member : LogChange
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public string UserId { get; set; }

        //[ForeignKey("UserId")]
        [Required]
        public virtual ApplicationUser User { get; set; }

        [Required]
        [MaxLength(200)]
        public string FullName { get; set; }

        public List<MarvelManager.API.Models.Entities.ReportSettings.ReportsSetting> ReportsSettings { get; set; }

        public MemberImage MemberImage { get; set; }

        public int DefaultProjectId { get; set; }

        public int DefaultTaskId { get; set; }

        public Constant.WeekStart WeekStart { get; set; }

        public int DateFormatId { get; set; }

        public List<MemberProjectRole> MemberProjectRoles { get; set; }

        public int TimeFormat { get; set; }

        public int SendEmailTime { get; set; }

        public bool IsWeeklyTimeEntryUpdatesSend { get; set; }

        public int? SendEmailDays { get; set; }
    }








public class MemberImage : LogChange
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public int MemberId { get; set; }

        [ForeignKey("MemberId")]
        public Member Member { get; set; }

        [MaxLength(200)]
        public string FileNameImage { get; set; }

        public byte[] ByteArrayAvatar { get; set; }

        public byte[] ByteArrayIcon { get; set; }
    }
public class ApplicationUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser
    {
        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Password { get; set; }

        public bool IsOwner { get; set; }

        public bool IsProjectManager { get; set; }

        public bool IsModuleLead { get; set; }

        public bool IsDeveloper { get; set; }

        public bool IsActive { get; set; }
    }



So what is it? My code structuring is wrong exactly where? Where did my understanding of this go wrong exactly. Can you help me point it out and direct me? Feels like a riddle.

Thanks in much anticipation,


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>