This project has moved. For the latest updates, please go here.

EF n-Tier Code Generation Error

Jun 2, 2014 at 10:00 PM
Edited Jun 2, 2014 at 10:32 PM
Hi,

I'm trying to try out the N-Tier EF framework. Looks cool.

I'm building the model and adding the code generation item using VS2013 and EF6, but am encountering an exception when running the code generation. This is the instruction I'm having trouble with:
Once the entity model exists a code generation template has to be added in order to generate all required code based on the entity model. For this purpose a Visual Studio item template exists.
The T4 template may be added either by using “add new item” or by simply right-clicking on the entity designer and selecting “Add Code Generation Item” from the context menu.
The code generation item gets created, but then when generation is running I get this exception:
Error   78  Running transformation: System.Exception: Missing property Namespace
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.EntityTemplate.OnRendering(EventArgs e) in c:\NTEF\BrightStar.NTEF\T4\NTierEF.EntityTT.CS.ttinclude:line 46
   at T4Toolbox.Template.Render()
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.DataModelCodeGenerator.CreateEntities() in c:\NTEF\BrightStar.NTEF\T4\NTierEF.DataModelCodeGenerator.CS.ttinclude:line 127
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.DataModelCodeGenerator.RunCore() in c:\NTEF\BrightStar.NTEF\T4\NTierEF.DataModelCodeGenerator.CS.ttinclude:line 100
   at T4Toolbox.Generator.Run()
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.NTierEntityGenerator.CreateDataModel() in c:\NTEF\BrightStar.NTEF\T4\NTierEF.NTierEntityGenerator.CS.ttinclude:line 303
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.NTierEntityGenerator.RunCore() in c:\NTEF\BrightStar.NTEF\T4\NTierEF.NTierEntityGenerator.CS.ttinclude:line 287
   at T4Toolbox.Generator.Run()
   at Microsoft.VisualStudio.TextTemplatingF4C3C31A8440ABB782A5E97AE2420F837EB23C005B62DA80FFB9B0F479F1E8B3744E6B55EF5236665ADB01D7937E56AD4943944CB845C586BE8551E0D7E73BDB.GeneratedTextTransformation.TransformText() in c:\NTEF\BrightStar.NTEF\BrightStar.NTEF\BrightStar.NTEF.Server.Domain.Edmx\AbsModel1.tt:line 22  c:\NTEF\BrightStar.NTEF\T4\NTierEF.EntityTT.CS.ttinclude    46  1   
Any thoughts on how to get around this? Or the root cause?

Thanks.

Lance Safford

<EDIT>
I'm trying to debug the t4 templates indicated in the exception message, I put a breakpoint on line 126 of NTierEF.DataModelCodeGenerator.CS.ttinclude. When the code reaches this point and I hover over entity.Name, the tooltip says it's null. But if I enter entity.Name in the Immediate window, it's populated. Of course, continuing results in the exception above.
    private void CreateEntities()
    {
        if (EntityTemplate != null)
        {
            foreach (EntityType entity in EdmUtility.ItemCollection.GetItems<EntityType>())
            {
                EntityTemplate.EntityName = entity.Name; <-- breakpoint here
                EntityTemplate.Render();
            }
        }
    }
</EDIT>
Coordinator
Jun 4, 2014 at 10:23 PM
Namespace property in NTierEF.EntityTT.CS.ttinclude should be set to the defaul namespace of your project "<MyProject>.Common.Domain.Model" automatically by the code generator in case of the default solution structure. Could you try and specify the path of your 'domain model project' in the code generation item "MyEdmxModel.tt" like this:
NTierEntityGenerator.DataModelProject = @"..\<project folder>\<project name>.csproj"
Aug 29, 2014 at 4:04 PM
Did you have any luck with this issue? I am having the same issue. I've tried updating the NTierEntityGenerator.DataModelProject = @"..\<project folder>\<project name>.csproj" to my project name with no luck.

Thanks,
Sam Mikkalson
Coordinator
Aug 31, 2014 at 11:54 PM
Edited Sep 1, 2014 at 12:01 AM
Hi Sam

Did you set the placeholders <project folder> and <project name> to their actual values? Can you make sure the resulting path atually exists and is pointing to your data model project file?

Please let me know whether it works.

Thanks, Christof
Sep 3, 2014 at 12:40 PM
I did get it but it took a little bit. When I was installing the add-ons for the projects Visual Studio got all screwed up. I'm not sure if some files were locked or what when I installed the components, but I uninstalled n-tier and t4, I ran devenv.exe /resetsettings and re-installed the components and now everything is working perfectly!

Thanks,
Sam
Coordinator
Sep 3, 2014 at 3:31 PM
Sam, thanks a lot for your confirmation.