Hugo
Hugo

Reputation: 2185

EF7 Navigation property with interface

Is Entity Framework 7 support Navigation property using interface type? I can find any answer to this on Google

ICollection<IMyInterface> ObjectCollection { get; set; }

Upvotes: 2

Views: 434

Answers (1)

Alexander Derck
Alexander Derck

Reputation: 14498

No, EF only knows models which are classes. Defining a collection of interfaces like you do is impossible. However, what you can do is write extension methods to query on which have interface constraints. For example:

IMyInterface { int Id {get; set;}}

public static IQueryable<T> Filter<T>(this IQueryable<T> q, int id) where T: IMyInterface
{
   return q.Where(q.Id == id);
}

Here T is a model which has to implement IMyInterface.

Upvotes: 1

Related Questions