Question

I have an Account class which will be used to indicate who is responsible for a certain entity. There will be many entities where this will be used, so I don't want to pollute my Account class with all these collections

public class Account
{
   public Guid Id{get; set;}
   public Guid Name{get; set;}
   ...
   public class EntityConfiguration : EntityConfigurationBase<Account>
   {   
       public EntityConfiguration()
       {
           // I do not want these!
           HasMany(a => a.As)   
              .WithOptional(x => x.Account)
              .HasForeignKey(x =>x.AccountKey);
            }
        }
    }
}


public class A 
{
   public Guid Id {get; set;}
   public Account Account{get; set;}
   // FK-Nav property
   public Guid AccountKey{get;set;}
   public class EntityConfiguration : EntityConfigurationBase<A>
   {   
       public EntityConfiguration()
       {
           // what should go here to specify the association to Account?
           ????
        }
    }
}

public class B 
{
   public Guid Id {get; set;}
   public Account Account{get; set;}
   // FK-Nav property
   public Guid AccountKey{get;set;}
      public class EntityConfiguration : EntityConfigurationBase<B>
   {   
       public EntityConfiguration()
       {
           // what should go here to specify the association to Account?
           ????
        }
    }

}

etc.
Was it helpful?

Solution

public class A 
{
   public Guid Id {get; set;}

   public Account Account{get; set;}
   // FK-Nav property
   public Guid AccountKey{get;set;}
   public class EntityConfiguration : EntityConfigurationBase<A>
   {   
       public EntityConfiguration()
       {

           HasOptional(x => x.Account).HasMany().HasForeignKey(x=>x.AccountKey);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top