2

I'm trying to move a project over to using Entity Framework, but to make it more fun, the project is in C++/CLR.

I've got a query

ObjectQuery<myData::Facility^>^ facQ = myContext->FacilitySet;

and I want to do this

int n = facQ.Count()

But I can't because c++ doesn't recognise extension methods using C# syntax. facQ->Count() doesn't work.

Using C# extension methods from managed C++/CLI shows the answer for user-defined extensions; but in this case, the extension is part of the .NET framework http://msdn.microsoft.com/en-us/library/bb349034%28v=vs.90%29.aspx.

Any ideas?

(I'm using visual studio 2008, and .NET 3.5).

Community
  • 1
  • 1
Melanie
  • 1,349
  • 2
  • 17
  • 27

1 Answers1

2

System::Data::Objects::ObjectQuery implements IEnumerable<T>. The Count() method you see in C# is from the System::Linq::Enumerable class.

using namespace System::Linq;

int n = Enumerable::Count(facQ);

Also see this answer, which shows a couple examples of calling other extension methods in that class.

Community
  • 1
  • 1
David Yaw
  • 27,383
  • 4
  • 60
  • 93