msawczyn / EFDesigner2022

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
119 stars 21 forks source link

Compiler Errors After Upgrade to v4.2.3.5 #61

Closed ab-tools closed 11 months ago

ab-tools commented 1 year ago

Hello Michael,

thanks for your continuous efforts on this project!

As I was curious to try your fixes for my reported issues #54 and #55, I've just updated from v4.2.1.3 to v4.2.3.5, but looks like this is making things much worse for me unfortunately...

Even following very simple test model generates broken code for me now: ConfigModel-Test.zip

grafik

This was working without problems in v4.2.1.3.

msawczyn commented 1 year ago

Not sure where you got the ConfigModel.tt file from, but it wasn't the one added to your project when you added the model. The .efmodel file has some differences that look suspicious as well.

Is this a copy of an old model and .tt that was edited? The model should work fine, but the T4 won't.

ab-tools commented 1 year ago

First thanks a lot for your quick reply, Michael, much appreciated!

I remember that a while ago you asked to do minor manual changes in this file, like removing these two lines:

#><#@ include file="EF6Designer.ttinclude" once="true"
#><#@ include file="EFCoreDesigner.ttinclude" once="true"

And changing #><#@ assembly name="EnvDTE" to #><#@ assembly name="Microsoft.VisualStudio.Interop".

But apart from that it should still be the same file created many years back. I'm using your tool for a pretty long time, so just updating to newer versions when they become available.

What would you suggest to do? Can I reset the .tt file to default while keeping the model in the designer intact?

msawczyn commented 1 year ago

Can I reset the .tt file to default while keeping the model in the designer intact?

Yes. Create a new .tt file and change its name. Do a slight edit to change the name of the model file to the one you're using.

Example:

><#@ EFModel processor="EFModelDirectiveProcessor" requires="FileName='EFModel1.efmodel'"

That should get you back on track. Normally you wouldn't need to do this, but the change you made was only meant to be a temporary change to get you over the problem you were experiencing earlier.

ab-tools commented 1 year ago

Thanks, Michael, done that now and reset the .tt file by creating a new model, renaming the file and changing the model file name within it manually thereafter - that worked and I can still generate the code.

However, the compilation errors in the generated code persist.

It is this line which was .UsingEntity(x => x.ToTable("Group_x_User")); with the old version and worked fine.

Now it is .UsingEntity<Dictionary<string, object>>(right => right.HasOne<global::Api.Data.Config.User>().WithMany().HasForeignKey(UserId).OnDelete(DeleteBehavior.Cascade),left => left.HasOne<global::Api.Data.Config.Group>().WithMany().HasForeignKey(GroupId).OnDelete(DeleteBehavior.Cascade),join => join.ToTable("Group_x_User")); and throws the compilation exceptions shown above.

What's the best way to get the models (I have two in production with similar issues) working again?

msawczyn commented 1 year ago

It sounds like there's a mismatch between the entity framework core version you're compiling with and the one you've told the model you're using. Can you check that?

msawczyn commented 11 months ago

Closing due to lack of activity.