0

Using MVC4, Entity Framework 5, I would ideally like every type to utilise an interface,

So I have my interfaces, one with a 'navigation' property to the other;

interface Ifoo has:

IUser User {get; set;}
int UserID {get; set;}

Lets say IUser only has UserID and UserName properties.

When implementing the Ifoo interface in a type, I use

public Iuser User {get; set;}
public UserID {get; set;}

Then, using EF5, I eager load the navigation propert, using my User type, which implements IUser:

db.Foo.where(x => x.id == id).Include(x => x.User)

But It tells me that:

A specified Include path is not valid. The EntityType 'Dal.Foo' does not declare a navigation property with the name 'User'.

However, If I change both the interfaces to implement the type directly, it works fine.

Is there a way around this so I can utilise interfaces?

1

1 Answer 1

0

I know this can be done using partial classes. so you can either use a partial class and ignore the interface, or just implement the interface in a partial class then inherit that. I recommend looking into T4 templates.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.