71

Closed

MustFix: Nesting an .edmx under a project folder causes .tt to stop generating after save

description

**This was fixed in the VS 2012 Update. You can get it from: http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update**

Repro steps:
  1. Create a project
  2. Add a project folder ("Models")
  3. Add a new .edmx ("Model1") into the project folder
  4. Add an entity ("car") and save.
Expected:
A new Car.cs file under Model1.tt, as well as related updates to Model1.Context.cs

Actual:
No updates to generated code

Workarounds:
  • Right click on .tt file and select "Run Custom Tool"
  • Drag .edmx out of the project folder

file attachments

Closed Dec 10, 2012 at 7:28 PM by moozzyk
Fixed in VSUpdate1. Ported to OSS version

comments

DavidObando wrote Aug 29, 2012 at 1:35 AM

The root cause of the problem is an innapropriate handling of the baseUrl on the VisitHierarchyItems() method in the HierarchyVisitor class. The baseUrl should not mutate throughout the execution of the search for the .tt files, but it is mutating when dependent files (or nested files) are found. The .tt files are being found by the algorithm via the file handlier ID and the filename string (EndsWith .tt) but the baseUrl is changed and reports an invalid URI. The problem can be fixed by not modifying the baseUrl inside HierarchyVisitor.VisitHierarchyItems(...). This is done by removing the lines that look like this:
        // Calculate new base Url
        if (!string.IsNullOrEmpty(path) && baseUrl != null)
        {
            baseUrl = new Url(baseUrl, path);
        }

jlerman wrote Aug 29, 2012 at 2:04 PM

aha! That's what the pattern is that causes this. I was on skype with a friend yesterday about this. It took a while to realize that her problems were because the code was not getting regen'd and I could not figure out why that wasn't happening. I couldn't reproduce the problem until I saw that it was the inner folder. Yes, that's her set up.

vlad325 wrote Sep 3, 2012 at 4:54 PM

Just curious, what release channel would be used for this and other fixes of this nature?

jciliberti wrote Sep 11, 2012 at 5:37 AM

David,

Any idea when this will be fixed. This almost drove me insane before I found this issue. Is there a patch we can install?

Thanks,
John

RoMiller wrote Sep 14, 2012 at 11:26 PM

We're not sure where or when we are going to release the fix for this yet. We understand it's very annoying and it's something we'll try and get out as soon as practical.

DavidObando wrote Sep 18, 2012 at 7:15 PM

To everyone who is hitting this problem:

As Rowan mentioned, we are still not sure where or when we will roll out a fix for this issue but in the mean time follow any of the two known workarounds:

1) Right click on .tt file and select "Run Custom Tool", or
2) Drag .edmx out of the project folder

Chevex wrote Oct 8, 2012 at 11:46 PM

There is actually another workaround option. I discovered this error because I upgraded an EF 4 EDMX to EF 5 by adding EF 5.x DbContext Generator to the project, which added T4 templates to the existing EDMX.

However, in the project file it did not mark them as DependentUpon the EDMX file so they did not appear under the EDMX node. Instead they appeared side-by-side with the EDMX in the folder. T4 generation worked fine until I manually went in and added the DependentUpon nodes in the project file.

Observe: http://www.youtube.com/watch?v=-boB5GhqfUI

Chevex wrote Oct 9, 2012 at 2:53 PM

My linked video would appear to be too high resolution for some people. Here is one at 1024 x 768 :)

http://www.youtube.com/watch?v=pHKSZximF8w

RoMiller wrote Nov 27, 2012 at 7:06 PM

This issue is fixed in Visual Studio 2012 Update 1 - http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update

We are leaving this work item active to track porting the fix to our EF6 code base.

boomer57 wrote Jan 9, 2013 at 6:18 PM

Running VS2012 Update 1, EF5 would not regenerate certain for certain stored procedures in my database. The only way I could get it to regenerate was to delete the given xxx_result.cs files, and only then would a regeneration work for them. If any MS EF team members see this, please look into this problem further. Thank you.

moozzyk wrote Jan 9, 2013 at 9:22 PM

@boomer57: Please, create a new issue and post repro steps. This issue has been closed and what you are describing does not seem to be related to the original issue where the code was not generated at all for edmx file nested in a folder.

Mike_B wrote Nov 1, 2013 at 12:38 AM

I am still experiencing this, or cetainly a similar problem using EF 5.0 in VS 2012 Update 3

We are conducting a proof of concept. The idea is to have a central sql server db (2012) with many standalone data collection wpf application clients. For the client side we are trialing sqlite and SqlCE 4.0. The central db will be updated when an internet connection is available, but no real-time central db updates will take place from the client.

We have, as you can see in the attached screen snap, an edm for each database with an extra class to create contexts to whichever db we want to connect to at the time. This all works well.

The steps to date are:
  • create the intital db with just a single table
  • generate the edm for each db in turn
  • all works as it should
  • alter the structure of all dbs to have a parent child table and PK-FK relationship
  • open each edm in turn, right click and update model from database
  • nothing happens
I have tried:
  • deleting the original table from the edm
  • right-clicking the tt files and selecting run custom tool
None of these actions performed the required update either. The only solution to date has been to delete all the edms and recreate them. This obviously is not a long term solution...

I am using a Win 7 Pro SP1 64 bit pc as my development machine. We are using EF 5.0 as SqlIte and EF 6.0 (as far as I can see) don't play together nicely yet.

Thanks in advance - I hope someone can help me.

moozzyk wrote Nov 1, 2013 at 6:18 PM

Hi Mike,

The only way I was able to repro this was to not to save the edmx file after changes. Saving Edmx files triggers running transformations of T4 templates associated with the a given edmx file. Also running the transformation manually (i.e. right-clicking the tt files and selecting run custom tool) is independent on the designer. Do you know if the transformation is not run at all or it runs but overwrites the file with the same contents (you can check it by running the transformation, checking the timestamp of the file, running the transformation again and comparing whether the timestamp of the file changed). If the transformation is not run at all it would mean that there is something wrong with your VS. If the transformation is run than it means but the contents of the file is not changed as expected it would mean that either the edmx file has not been saved or the T4 template is not actually using the file you are changing. The T4 templates contain the following line:

const string inputFile = @"Model1.edmx";

this line points to the edmx file that is supposed to be used as the source of the transformation. If this line does not correspond to the name of the edmx file you are modifying or you have a different file with the same name that is for some reason being found first it will be used for the transformation and you will most likely not get the expected results.

Hopefully the above information will help you resolve the issue. Note that what you are seeing is not related to this work item which is specifically about transformation not being invoked when the edmx file is in a subfolder which in your case does not apply since you don't seem to have nested edmx files.

Mike_B wrote Nov 5, 2013 at 12:20 AM

Thanks @moozzyk, very helpful!

I realise my problem was not directly related to the original issue fixed in the VS2012 Update 1, but I could find nothing similar in all my searches.

Today I can get the changes to the database to be recognised when I try to update the model. And saving straight away regenerates the classes as expected. Maybe that was a part of the problem.

Dunno what was going on the other day, but nothing was happening - very frustrating...

Again, your help is very much appreciated

Mike