Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Errors while generating entity code from efmodel built using existing codebase #150

Closed
npagare opened this issue Feb 15, 2020 · 17 comments
Closed
Labels
question Requesting information released Issue is resolved in a current release
Projects
Milestone

Comments

@npagare
Copy link

npagare commented Feb 15, 2020

Hi @msawczyn , good afternoon ! Happy Saturday !

As mentioned in my #81 - I am trying to incorporate EF Core (v 3.1.1 now) in my Mobile App's Data services layer.

The diagram below shows the overall process I am following in getting a stable state of generating Entities using your EFDesigner tool and getting ready for generating SQLite database via EFCore migrations (which I have been trying to avoid on a parallel attempt to do that only via dbcontext scaffolding route).

Per diagram, after saving the efmodel I am facing number of errors in the generated code. Your help for in addressing my queries around that would be truly appreciated -

  1. Does EFDesigner code generation has influence specifically to support SQL Server target as the database ? Which I am ok when read to take the effort for database behind my APIs but on mobile my target database is SQLite.

  2. A new non-default constructor is created where initialization of the member variable including null check, and any other entity association is done. Apparently this constructor doesn't have any parameters. Is this by design ? The Create method attempts to call this constructor but compilation fails as there are not params in the non-default constructor. The error is "already defines a member called .ctor with the same parameter types.

  3. Referred local variables in the new constructor are missing their definition -
    e.g. if (string.IsNullOrEmpty(message)) throw new ArgumentNullException(nameof(message));
    this.Message = message;
    The "message" is suppose to be a member variable based on the entity property "Message". But, the generated class doesn't have a member variable by name message. I checked across the class files and those were missing,

  4. If I drop an updated class file from the first step (blue color blocks on the left in my diagram) on the left series of step onto efmodel, the generated code has duplicate entry for the collection causing errors.

  5. How to stereotype entities as enum after the existing class is dropped on efmodel diagram?

  6. In the lieu of SQLite - how to use associations to depict 1:1, 1:* and : relationships ?

  7. Can warning such as missing documentation per entity attribute be shown on the left of the existing icons per attribute that way we can see both type of attribute and any missing input via warning sign ?

  8. SQLBrowser utility supports exporting tables as CSV, Create Indexes, Views on SQLite db. Will you consider supporting such feature in the EFDesigner ?

I would appreciate if you would allow me to add additional errors in this github issue as I follow this path as mentioned in the process diagram below.

Will you please not close this issue until I get to fully create a stable entity model (as outlined in the diagram below) ?

image

@msawczyn msawczyn added the investigating Looking into this label Feb 17, 2020
@msawczyn
Copy link
Owner

Wow. That's a lot to take in, but let me see what I can do.

Does EFDesigner code generation has influence specifically to support SQL Server target as the database ?

The designer is (should be?) completely persistence-agnostic. The code it generates stops at the Entity Framework level, and the persistence mechanism, be it SQL Server, Oracle, SQLite or in-memory, is handled by EF.

A new non-default constructor is created where initialization of the member variable including null check, and any other entity association is done. Apparently this constructor doesn't have any parameters. ... Referred local variables in the new constructor are missing their definition

A constructor is created when any required properties are modeled, so that the end user can provide those parameters at the beginning of the object's life. There was an issue in one release where the constructor parameters weren't getting calculated correctly, but that's been corrected in 2.0. In the case of the object having required parameters, we still need to generate a default constructor to make Entity Framework happy, but that constructor doesn't have to be (and isn't) public.

If I drop an updated class file from the first step (blue color blocks on the left in my diagram) on the left series of step onto efmodel, the generated code has duplicate entry for the collection causing errors

I haven't seen that behavior, Can you give me a step by step, with example data?

How to stereotype entities as enum after the existing class is dropped on efmodel diagram?

Enums and classes are different element types, and you can't change one into the other. But dropping an enum onto the model should generate an Enum element - is that what you're asking?

In the lieu of SQLite - how to use associations to depict 1:1, 1:* and : relationships

See above - storage type isn't a concern, and the actions you take when modeling aren't aware of the persistence mechanism. I'm not familiar with SQLite, though ... if the EF driver doesn't support associations, that will have to be an enhancement made in that driver.

Can warning such as missing documentation per entity attribute be shown on the left of the existing icons per attribute that way we can see both type of attribute and any missing input via warning sign ?

I'm afraid that's more of a real estate problem ... there isn't a whole lot of space to work with in the void area between the attribute text and the edge of the element box. I had to make the design choice to replace the attribute icon with the warning icon, although I'd really like to show both.

SQLBrowser utility supports exporting tables as CSV, Create Indexes, Views on SQLite db. Will you consider supporting such feature in the EFDesigner ?

You can already flag that a property should be indexed (although there isn't support for multi-property indices). Exporting data as CSV is a runtime thing rather than a modeling thing, so it's out of scope, and views are too low level for what the modeler does ... EF supports database views (if persistence happens on a database) as a read-only data source, and EFCore has better support for that than EF6, although both can handle it.

Will you please not close this issue until I get to fully create a stable entity model

Sure. No problem.

@msawczyn msawczyn added question Requesting information bug Confirmed bug pending release Issue is resolved in the current codebase, will be published with the next release and removed investigating Looking into this labels Feb 20, 2020
@npagare
Copy link
Author

npagare commented Feb 21, 2020

Thanks Michael. I will work on getting you a sample repro on this issue. For now, immediate pain is there are two default constructors created. There is a protected default constructor and a public default constructor. The issue is in the public default constructor which gets called in a static method create that returns a new instance of the class using the public constructor where it is trying to pass required parameter. This is that public instructor which should have parameters which I don't see in the generated code.

@msawczyn msawczyn added this to the 2.0.0.0 milestone Feb 24, 2020
@msawczyn msawczyn added released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Apr 11, 2020
@npagare
Copy link
Author

npagare commented Apr 11, 2020

Hi @msawczyn - I am sorry for not providing the repro yet. Things have been just up side down on priorities with given situations around all of us.

Will you please keep this issue open. I can't reopen it as I am not an owner on this repo. I would like to verify your fix - if that's ready and provide you with my findings.

Thank you

@msawczyn msawczyn reopened this Apr 11, 2020
@msawczyn
Copy link
Owner

No problem. Happy to do so.

@npagare
Copy link
Author

npagare commented Apr 11, 2020

Thank you @msawczyn.
Tried to update the package but the VS marketplace is giving an error - not found.
Are you in the process of publishing the update ?
image

@msawczyn
Copy link
Owner

msawczyn commented Apr 11, 2020 via email

@npagare
Copy link
Author

npagare commented Apr 12, 2020

Yes. Give it a few hours.

On Sat, Apr 11, 2020, 2:01 PM IoTFier @.***> wrote: Thank you @msawczyn https://github.com/msawczyn. Tried to update the package but the VS marketplace is giving an error - not found. Are you in the process of publishing the update ? [image: image] https://user-images.githubusercontent.com/26844611/79051190-6e3dc500-7bf4-11ea-9a16-77139c9e33b1.png — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#150 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANSGCXXF3RHREDJE2XUCM3RMCV6JANCNFSM4KV4XT2A .

Just curious ... I still don't see the nuget with 2.0 update in the Marketplace.
Thanks

@npagare
Copy link
Author

npagare commented Apr 13, 2020

Hi @msawczyn , the dragging of my existing POCO on .efmodel / design pane doesn't show up the corresponding class.

Thank you

@msawczyn
Copy link
Owner

Thanks for the report. I'll look into it. To clarify, you're dragging a .cs file from the Solution Explorer onto the design surface and it doesn't add the class? Or are you dragging from the Windows File Explorer? Both should work, but there have been a lot of changes to the drag/drop code to support the new multi-diagram feature and something may have slipped through the cracks.

@msawczyn msawczyn removed the released Issue is resolved in a current release label Apr 13, 2020
@npagare
Copy link
Author

npagare commented Apr 13, 2020

HI @msawczyn - I removed a portion of my prev comments. I guess that was from a clipboard buffer. My apologies for that.

I am dragging .cs file from the solution explorer onto the design surface. As I digged it further, it is creating .cs file (for some of my .cs classess) but not showing the entity added on the design panel.
For some of my .cs file the drag and drop capability is throwing errors which I haven't dig much into it yet.

As I had offered this earlier, would you be interested in a screen share session? That may be more worthwhile for our efficiency and productivity of this capability ?
Thoughts ?

Thank you,

@msawczyn msawczyn modified the milestones: 2.0.0.0, 2.0.0 Apr 13, 2020
@msawczyn msawczyn added investigating Looking into this and removed bug Confirmed bug labels Apr 13, 2020
@msawczyn msawczyn added this to Enhancement Requests in EFDesigner via automation Apr 13, 2020
@msawczyn msawczyn moved this from Enhancement Requests to Bug Reports in EFDesigner Apr 13, 2020
@msawczyn
Copy link
Owner

Sorry, but I won't be able to do a screen share. Time is tight right now and I can't guarantee when I'll have time to look into this ... likely tonight, which may be 8 hours from now. The perils of side projects.

@npagare
Copy link
Author

npagare commented Apr 13, 2020

Sounds good. Thank you.

@msawczyn
Copy link
Owner

Fixed in 2.0.1

@msawczyn msawczyn moved this from Bug Reports to Done in EFDesigner Apr 14, 2020
@msawczyn msawczyn added the released Issue is resolved in a current release label Apr 14, 2020
@msawczyn msawczyn modified the milestones: 2.0.0, 2.0.1 Apr 14, 2020
@npagare
Copy link
Author

npagare commented Apr 14, 2020

Thank you @michael-sawczyn.
Waiting for the marketplace to reflect the new version 2.0.1

@msawczyn msawczyn added pending release Issue is resolved in the current codebase, will be published with the next release and removed investigating Looking into this released Issue is resolved in a current release labels Apr 15, 2020
msawczyn added a commit that referenced this issue Apr 16, 2020
@npagare
Copy link
Author

npagare commented Apr 16, 2020

Hi @msawczyn, good morning !

Another set of errors I when I drop .cs file on efmodel design panel and try to save the diagram (with no entities shown on the panel) are -

  1. Principal/dependent designations must be manually set for 1..1 and 0-1..0-1 associations.
  2. Class has no identity property in inheritance chain

@msawczyn
Copy link
Owner

  1. It's always the case that you need to make a decision for 1..1 and 0-1..0-1 associations. There's no way to determine which is principal by convention.
  2. Dropping a .cs file is just adding a class. Since you're taking charge of all the properties, no extra properties are added for you.

Essentially, both of the behaviors you're seeing are by design.

@msawczyn
Copy link
Owner

BTW, this chain is getting quite long and convoluted. I'm going to close it now. If you have other bug reports I would love to see them, but they need to be entered each as separate reports so they can be tracked and not get lost.

@msawczyn msawczyn added released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release labels Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Requesting information released Issue is resolved in a current release
Projects
EFDesigner
  
Done
Development

No branches or pull requests

2 participants