NadavRub
NadavRub

Reputation: 2610

EF edmx inheritance

Use-case

  1. Implement a DAL around Entity Framework to enable future ORM replacement
  2. The DAL is to partially expose EF generated classes
  3. Entity-Framework to be used with Model-First ( DB doesn't exist yet )

Analysis

Example

class UserInfo
{
   public int      UserId       { get; set; }
   public string   DisplayName  { get; set; }
   public DateTime CreationTime { get; set; }
   public DateTime LastModified { get; set; }
}

class UserProfile : public UserInfo
{
   // I don't want this to be directly exposed out of the DAL
   public string ConfirmationToken { get; set; }
   // Navigation property
   public virtual ICollection<UserVariant> Variants { get; set; }
}

class DAL
{
   // Returned value include no navigation properties
   public UserInfo GetUser(int UserId) { ... }
}

Problem to resolve

Is it possible to define inheritance @ the '.edmx' in such a way that 'UserProfile' will be used as the reference for the DB table rather than UserInfo ?

Upvotes: 1

Views: 149

Answers (1)

NadavRub
NadavRub

Reputation: 2610

Solution was to convert 'Model-First' to 'Code-First' and have the DB Model class inherit from an interface exposing the selected methods ( non navigation attributes ), this interface would then get exposed by the DAL avoiding out-of-context Navigation attr access.

Unfortunately, I didn't find a Model-First solution for the above mentioned problem and had to go Code-First .

Upvotes: 1

Related Questions