O'Reilly Forums: How To Test If Ef Creates Dynamic Proxy - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Test If Ef Creates Dynamic Proxy

#1 User is offline   underwater 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 10-November 11

Posted 20 November 2012 - 06:09 AM

In Programming EF : DbContext (p66) it says "Entity Framework creates the dynamic proxy for change tracking, it will implement the IEntityWithChangeTracker interface".

As a quick test, it suggests using the below code

// Example 3-18. Testing for a change tracking proxy
private static void TestForChangeTrackingProxy()
{
using (var context = new BreakAwayContext())
{
var destination = context.Destinations.First();
var isProxy = destination is IEntityWithChangeTracker;
Console.WriteLine("Destination is a proxy: {0}", isProxy);
}

However, VS2012 seems to raise a warning for the line [var isProxy = destination is IEntityWithChangeTracker;] complaining that : Suspicious type check: there is no type in the solution which is inherited from both (a reference to my class and to IEntityWithChangeTracker"

At runtime although the destination is in fact a generated proxy, the expression (destination is IEntityWithChangeTracker) returns False !

Am I missing anything ?

THanks for any guidance or suggestions.
0

#2 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 313
  • Joined: 17-September 08

Posted 23 December 2012 - 08:06 AM

I've pulled the example in to VS2012 and updated it to EF5. I see this as a compiler warning, but the solution compiles and the method runs as expected.

I've got Resharper running so I don't know if the warning is coming from R# or from Visual Studio. I'm not worried about it. If you want to dig deeper, ask on Stackoverflow and be sure to tag the post as entityframework. The EF team watches SO for EF questions.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users