Entity FrameWork – Cannot convert lambda expression to type ‘string’ because it is not a delegate type

October 9, 2012

I’ve just been working through some Entity FrameWork tutorials and ended up with an error whilst trying to use .Include() (Eager loading instead of lazy loading)

Cannot convert lambda expression to type ‘string’ because it is not a delegate type

This is because the overload on System.Data.Entity.DbSet expect a string – Which is the name of the entity to eager load. I was passing in a lambda expression. I could of course just passed in a string, but this does not give me any compile time safety if my model ever changes.

The solution is to add a using statement:

using System.Data.Entity;

System.Data.Entity.Include() accepts a lambda expression, so my original attempt: …Include(a => a.County) compiles and works.

 

 

 

using System.Data.Entity;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: