Entity Framework 6.0 not auto-generating 'On Changing' or 'On Change' partial methods for table fields



I am generating entity framework classes from a SQL Server table. However I am not seeing the partial methods like the example below:

partial void OnFirstNameChanging(global::System.String value);
partial void OnFirstNameChanged();

I am using VS2012 & EF6.0. Many online examples talks about over-ridding these partial methods in newly created partial classes to put validation logic. But I can't find these methods in my auto-generated code. Is this something that's manually added in EF6.0? Will appreciate feedback. Thanks.

12/31/2013 6:57:08 PM

Popular Answer

You are using wrong generator. Those methods are only generated by EntityObject based generator (the one which is deprecated). Default generator uses POCO classes where these partial methods are not generated - you can modify the generator to add them (it is a T4 template).

To use EntityObject generator:

  • Delete current .tt file stacked under your EDMX.
  • Open EDMX, right click in the designer and select Add code generation item from context menu.
  • If you don't see EF 6.x EntityObject Generator in Visual C# Items select Online and search for this generator.
  • Install the generator and use it.
  • Now your generated entities should support those partial methods.

Opening .tt file and searching for Changing and Changed words will give you and idea what is necessary to do in case of adding those methods to POCO generator.

1/1/2014 12:55:34 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow