1

I have an EF4.1 database first application, and the .ToString() method is only giving me the reflected type, and not the SQL query.

How do I make my application show me the Linq query in SQL format?

I've added version 4.1 of C:\Program Files (x86)\Microsoft ADO.NET Entity Framework 4.1\Binaries\EntityFramework.dll to my project. I'm guessing the ToString feature is added by an extension method, but even when I add "Using system.data.Entity" I'm unable to getthe string output to work.

Does this mean ToString only works for Code First deployments?

  public IEnumerable<CompanyDetail> GetAllCompanies(int? startPage, int? stopPage, string Filter, int? MaxResults)
    {
        var t = from c in _entities.CompanyDetail
                select c;

        string test = t.ToString();

        var t2 = _entities.CompanyDetail;

        string test2 = t2.ToString();
        return t.ToList();
    }
Community
  • 1
  • 1
makerofthings7
  • 60,103
  • 53
  • 215
  • 448

1 Answers1

1

I can confirm that it works for database first applications.

I am guessing your code is still using the EF 4 classes since you didn't mention adding the EF 4.1 DbContext generator to your model. If that's the case, you can right-click on the model, choose "Add Code Generation Item..." and select the ADO.NET C# DbContext Generator. If you don't see it in your installed templates, look for it under Online Templates.

Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
  • I honestly have no idea what I would do without S.O. I spent hours looking for this in VS and online. Much appreciation man – makerofthings7 Nov 15 '11 at 01:55
  • Seems like there may be a bug in EF4.1, possibly a reflection issue (or implementation issue) with Appfabric caching http://stackoverflow.com/q/8131195/328397 ... in case you want to know... – makerofthings7 Nov 15 '11 at 06:02