EF LINQ to PostgreSQL Include

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

EF LINQ to PostgreSQL Include

Post by damon.cognito » Tue 23 Jun 2015 22:37

As I understand it you should be able to construct an eager laoding statement like:

Code: Select all

    var blog1 = context.Blogs.Where(b => b.Name == "PostgreSQL") 
                        .Include(b => b.Posts).FirstOrDefault();
but I can only get it to work if I use a string (which is obviously not great). I feel I'm missing something obvious here...

Code: Select all

    var blog1 = context.Blogs.Where(b => b.Name == "PostgreSQL") 
                        .Include("Posts").FirstOrDefault();
(EF to PostgreSQL 9.3.4)

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF LINQ to PostgreSQL Include

Post by Shalex » Wed 24 Jun 2015 13:51

damon.cognito wrote:As I understand it you should be able to construct an eager laoding statement like:

Code: Select all

    var blog1 = context.Blogs.Where(b => b.Name == "PostgreSQL") 
                        .Include(b => b.Posts).FirstOrDefault();
This functionality is implemented by Microsoft via the DbExtensions methods: https://msdn.microsoft.com/en-us/librar ... 03%29.aspx. Just add the necessary namespace and try again:

Code: Select all

    using System.Data.Entity;
//...
    var blog1 = context.Blogs.Where(b => b.Name == "PostgreSQL") 
                        .Include(b => b.Posts).FirstOrDefault();

damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Re: EF LINQ to PostgreSQL Include

Post by damon.cognito » Wed 24 Jun 2015 17:27

Brilliant thanks - knew I was missing something. Just in case anyone else is looking at this, the include appears to have to be before the Where.

cheers!

Post Reply