none
Intellisense not showing navigation properties when using a lambda with Include() - any idea why? RRS feed

  • Question

  • Hello,

    I have been trying to use the new version of Include() that comes with EF4.1, where you can use a lambda instead of a string, but am having trouble with Intellisense not working.

    I tried a simple console program, added an EF model for the Northwind database, and added a a code generation item for the ADO.NET DbContext Generator. I ended up with code like this...

    using System;
    using System.Linq;
    using System.Data.Entity;
    
    namespace EF4._1Test {
      internal class Program {
        private static void Main(string[] args) {
          NorthWindEntities db = new NorthWindEntities();
          IOrderedQueryable<Product> products = db.Products
            .Include(P => P.ProductName)
            .Take(20)
            .OrderBy(P => P.ProductName);
          Console.WriteLine("Found " + products.Count() + " product(s)");
          foreach (Product p in products) {
            Console.WriteLine("  " + p.ProductName + " is in category " + p.Category.CategoryName);
          }
        }
      }
    }
    


    The problem is that when I try to type the lambda in the Include() line, Intellisense only shows me the ProductName property, which is a string, and doesn't show any of the navigation properties. Logically enough, if I try and run the code shown above, I get a runtime exception, as ProductName is not an entity.

    I can manually type a navigation property's name in the lambda, and it works fine, but Intellisense doesn't recognise it. As you can imagine, this makes coding a lot harder.

    Here is a screen shot of the Intellisense problem...

    Anyone any idea what's going wrong here? Thanks


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, January 9, 2012 2:06 PM

Answers

  • Hi Mr Yossu;

    It sounds to me like you have the tool ReSharper installed in your Visual Studio environment. It is a known issue with the current version 6.1. If this is your case you can goto the menu ReSharper -> Options and in that window select IntelliSense in the Environment node and select Visual Studio and not ReSharper. Then you will have the selections you are looking for.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Mr Yossu Monday, January 9, 2012 5:02 PM
    Monday, January 9, 2012 4:56 PM

All replies

  • Hi Mr Yossu;

    It sounds to me like you have the tool ReSharper installed in your Visual Studio environment. It is a known issue with the current version 6.1. If this is your case you can goto the menu ReSharper -> Options and in that window select IntelliSense in the Environment node and select Visual Studio and not ReSharper. Then you will have the selections you are looking for.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Mr Yossu Monday, January 9, 2012 5:02 PM
    Monday, January 9, 2012 4:56 PM
  • Thanks Fernando, that was it!

    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, January 9, 2012 5:03 PM
  •  

    Not a problem Yossu, glad I was able to help.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 9, 2012 5:04 PM