-
Notifications
You must be signed in to change notification settings - Fork 60
Issues with Designer, VS2019, .NET Core 3.0 #104
Comments
Hi Alex, You said you're using EFCore. That technology is different than the older EF6, and only handles one inheritance strategy (table-per-hierarchy), so you won't see that option. Automatic migrations, proxy generation and database initializers aren't supported in EFCore (yet?) either, so those options are disabled as well. The designer needs to be updated to handle lazy loading, introduced in EFCore 2.2, as the EFCore support is currently at the 2.1 level. Since EFCore only uses TPH inheritance, you'll see a table structure I don't think you're anticipating when you use inheritance. Running the 'add-migration' procedure will create a base class table with all properties from inherited classes. If you use a common base class for all your entities, you'll end up with only one table :-) ! Not the designer's doing ... that's Entity Framework. I'm pretty confident that will change as it evolves, but don't know what their timeline is on that. I'll look into the issues you've mentioned and see what's happening there. Thanks for the report! |
Hi Michael, tnanks for your prompt and kind reply. From what you're saying I will skip the inheritance dreams for the moment. I'm thinking about making all the classes implement an interface with the desired Created/Modified properties, so that they can all be cast to that interface. Thank you again, |
What you're wanting to do is a solved problem, and there are a lot of good solutions out in open source land that can make your life simpler. Using the designer, as well, gives you the means of modifying the generated code to add properties automatically without modifying the classes, via edits to the T4. Search around for 'audit' and entity framework. I'm sure you'll find some things that can help. |
Well, I had a look in your code and added this block in the GenerateEFCore function in the EFCoreDesigner.ttinclude file and it works! But please let me know if I'm doing something that could get me in trouble...
|
An interesting approach but, as I'm sure you've discovered by now, not the most correct way of doing this. The first time you generate code, you'll see the code you were expecting, and the attributes will be added to the model. Modifying the model from the T4 isn't really something you want to do; the T4 is the consumer of the data in the model and, if the model could be made readonly when the T4 runs we'd certainly do that to enforce the dependency direction. Should the model somehow be saved at this point, you'll have the issue of the properties being added again the next time you generate code. Since duplicate names aren't allowed, you'll get unique names based on the name you asked for, and you'll have to delete them. To take this approach, it would be more like:
There are a couple of other ways you could do this. You could just output the code for these properties without adding them to the model, in the If you don't need the properties in your classes, you could just add the properties as shadow properties so they show up in the database but not in the code. No modification of the T4 is needed for that; instead, you would use the technique found in the EF Core docs and implement that in the If you do decide to modify the Regarding the errors you've found, can you give 1.3.0.7 a try? I can't seem to replicate what you're seeing, so it might be fixed already. Thanks again for the report. |
Hi Michael, I have added a MaxLength to all my string properties but the error insists, it shows up 10 times in the Error List window. I can send you the solution to check for yourself. Best, |
That would be great. I don't see that behavior happen. Thanks!
…On Mon, Oct 7, 2019, 7:14 AM alprinias ***@***.***> wrote:
Hi Michael,
Now, with 1.3.0.7 it has started giving me the error
Invoke validation method 'StringsShouldHaveLength' failed due to a null
reference being accessed.
I have added a MaxLength to all my string properties but the error
insists, it shows up 10 times in the Error List window.
I can send you the solution to check for yourself.
Best,
Alex
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#104?email_source=notifications&email_token=AANSGCUYC5JJKGFRVFS6W4DQNMKZRA5CNFSM4I52YPYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAP5PYI#issuecomment-538957793>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANSGCWEL76AGOIMQJHFE3LQNMKZRANCNFSM4I52YPYA>
.
|
Hi Michael, where can I send you the solution in private?
Alex
|
This morning I started VS again, after having shut down, and the validation errors had gone. However, as soon as I tried to add properties via code the "object reference..." error showed up. After deleting the entity from the designer and trying to validate, I get two of the errors I mentioned yesterday. |
Alex, please add it to an accessible location (e.g., Google drive, etc.) and send me the url at michaelsawczyn[at]gmail.com Thanks! |
That was a huge help. A couple of things:
Thanks for sending that sample file - it did the trick. |
Glad you could reproduce and it helped! |
Coming soon... |
Continuing with 1.3.0.7 for the moment, have removed the enumeration and my model is now slightly more complicated. I saw another symptom, which I don't know if it has to do with the problematic 1.3.0.7 version or it is a problem with my model. I had two Owned Entities and with those in the model I could not run Add-Migration, I was getting a NullException. As soon as I removed them, it all worked fine. |
Fix available for review in v1.3.0.8-pre |
Hello and thank you for a great tool.
I just started using it a couple of days ago for a new project with VS2019 Community and .NET Core 3.0. I followed the docs and created a couple of entities, all fine. I came across a problem when I tried to create an overall "BaseEntity". My idea is to place a few properties that will be shared amongst all other entities, things like the primary key Id (Int32) and CreatedBy, ModifiedBy (String) and CreatedOn, ModifiedOn (DateTime). I noticed an "unstable" behaviour when I added the last four by "Add properties Via Code" functionality, where I got an "object reference ..." error. I added by code only one of the String properties and it worked, so I thought that it was the datetime properties, and then tried to add them manually, i.e. create a new property, change its name from Property1 to CreatedOn, make it Required, but when I tried to change its Type from String to DateTime I got an error saying "cannot set property value on a deleted element". After a couple of tries, deleting the property and recreating it,I finally managed to do what I intended.
And then, I tried to connect with an inheritance link my "Country" entity (with just two properties, Id and Name) with the BaseEntity. Then Visual Studio itself crashes, and when it restarts it shows the yellow header with "A previous session ended unexpectedly. Disabling the extension Entity Framework Visual Editor 1.3.0.6 might help." Edit: after I removed the property Id from the child entity, it worked alright.
The other question is whether the BaseEntity will be created as a table in the DB or it will just have its properties added to all the inheriting tables.
The designer surface is missing the properties described in the documentation "Inheritance Strategy", "Lazy loading Enabled" and "Proxy Generation Enabled" from teh Code Generation group. Also "Automatic Migrations Enabled" and "Database Initializer Type" are missing from the Databse group. Should they be there or is the documentation outdated?
All the best,
Alex
The text was updated successfully, but these errors were encountered: