❔ Entity Framework relationship problem between entities.
Hello, I am currently doing an Entity Framework internship and I have a relationship problem between entities.
In the beginning we are given a base class "Entity", which has certain properties, its diagram is clear and simple. I associate the original class:
This class is inherited by the "User" class. Code:
My problem is the following assignment: "Create the necessary relationships between "User" and "Entity", where instead of using "String" for the properties (CreatedByUser, EditedByUser, DeletedByUser) use an instance of the "User" class.
I've been having trouble posing this assignment correctly mainly because of the inheritance present between User and Entity. What would be the correct way to approach this relationship?
15 Replies
looks like a poorly posed question to me. An abstract class with all concrete and public properties?
So you cannot override anything, and you cannot choose what to expose when inheriting it
I don't know what to answer. There are more classes that will also inherit from the Entity class, the question itself doesn't seem clear to me either, and that's why I don't know how to set up the assignment correctly. Before asking here I looked for more answers from people doing the same course on github and no one did that part. Since I don't have direct support for doubts, I ended up here thinking that it was a lack of knowledge on my part.
May I abuse and ask how you would do the implementations of the properties present in Entity? Totally ignoring the example I supplied, I'm curious how you would do it from scratch.
Entity is fine, apart from the default dates. But entity is fine, assuming that all specialisations don't need/want to do something weird like
where instead of using "String" for the properties (CreatedByUser, EditedByUser, DeletedByUser) use an instance of the "User" class.Are you absolutely sure this is correct?
This class is inherited by the "User" class. Code:?
Yep, before the assignment, inheritance was already being done that way. And it only asks to modify the mentioned methods.
The only thing that makes sense to me is:
or it literally just means change the property types
In this case Entity Framework will not work, I get the error: The entity type 'User' requires a primary key to be defined. And my doubt is born right there, what would be the correct way to establish that relationship?
it has primary key - public Int64 Id { get; set; }
if EF doesnt detect that, then thats a bit crappy. Add it with the model builder.
I still have the same doubts, but thanks anyway for trying to help me.
also, ef doesn't work with abstract
classes have to be creatable
mmm wouldn't it be cyclic
what is cyclic?
because Entity has a User, but User is a Entity
how do you create one without creating the other
you dont create entity, its abstract base class...
exactly, but ef doesn't know this
you are asking it to write it in the db
might as well create it when recovering it
eh?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.