How to get property change notifications with EF 4.x DbContext generator

前端 未结 8 918
忘了有多久
忘了有多久 2020-11-27 18:29

I\'m playing around with Entity Framework 4.3, and so I am using the DbContext Generator to create the context and entity classes.

With the default EF 4 code genera

8条回答
  •  心在旅途
    2020-11-27 19:27

    The solution from Anders above works, however there are a couple of gotchas I found during the process:

    In Step 1 where it says "Add the following to the CodeStringGenerator class", only the "public string Private(..." function can be added because the other two already exist. So, you need to find them and replace those two functions not add them, otherwise you'll get errors. To find exactly where you need to put them, do a search for "public class CodeStringGenerator", and look for the functions underneath that.

    In step 2 "Add the following to the generator", you only need to add the "using System.ComponentModel" line, and the lines from (and including) "public event PropertyChangedEventHandler...". Again, the other lines already exist, you will find them near the top of the .tt file.

    In step 3 "And a bit further down", both of those "foreach" loops also already exist, so they must be replaced and not added. Ultimately only one line is added to each foreach loop, "<#=codeStringGenerator.Private(edmProperty)#>" and "<#=codeStringGenerator.Private(complexProperty)#>" in each loop respectively.

    Also, don't replace the wrong loop, there are two additional loops above the ones you need to replace which both cycle through the same objects... make sure you replace the correct ones :-)

    I thought I would mention this because as an MVVM / EF novice (used to use NHibernate) I had to make these adjustments for it to work.

提交回复
热议问题