You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got a problem with mapping my relation schema with multi-language support with EF Core ORM and desperately looking for help. I have an Event table (int id, text name, int typeId) and EventTypeLocale table (int id, text locale, text name).
To explain why I cannot restructure my db schema to attach EventId to EventTypeLocale table - there is an example content in EventTypeLocale:
And Event table has info about session + its type - typeId that should reference EventTypeLocale with FK. But, as you can see from the example data - there will be several database rows by one id (since there is a composite key id + locale). I want to load the type in all locates into the EventTypeLocales collection.
I have two classes
public class Event
{
public int Id { get; set; }
public string Name { get; set; }
public int TypeId { get; set; }
public List<EventTypeLocale> EventTypeLocales { get; set; }
}
public class EventTypeLocale
{
public int Id { get; set; }
public string Locale { get; set; }
public string Name { get; set; }
}
The complex part is to configure it in the Context : DbContext class. Could you help me to configure such a relation? Is there such a possibility with EF Core? Or how should I change the model/(db schema but less desirable) to achieve what I want?
The question is also posted on SO and I asked another question a year ago where I got a working solution for fetching, but it restricts updating the FK field (typeId) because it is set up as a principal key. The "working" solution for fetching is below:
VitaliiIsaenko
changed the title
Would this multi-language db schema be possible to setup in EF Core 5?
How to setup the DbContext to work with multi-language value tables
Nov 2, 2020
VitaliiIsaenko
changed the title
How to setup the DbContext to work with multi-language value tables
How to setup the DbContext to work with multi-language value tables?
Nov 2, 2020
@VitaliiIsaenko That mapping looks correct and I can't think of a way of doing this that doesn't make TypeId an alternate key. Therefore, this is probably a duplicate of #4073
I got a problem with mapping my relation schema with multi-language support with EF Core ORM and desperately looking for help. I have an
Event
table(int id, text name, int typeId)
andEventTypeLocale
table(int id, text locale, text name)
.To explain why I cannot restructure my db schema to attach
EventId
toEventTypeLocale
table - there is an example content inEventTypeLocale
:And Event table has info about session + its type -
typeId
that should referenceEventTypeLocale
with FK. But, as you can see from the example data - there will be several database rows by one id (since there is a composite keyid + locale
). I want to load the type in all locates into theEventTypeLocales
collection.I have two classes
The complex part is to configure it in the
Context : DbContext
class. Could you help me to configure such a relation? Is there such a possibility with EF Core? Or how should I change the model/(db schema but less desirable) to achieve what I want?The question is also posted on SO and I asked another question a year ago where I got a working solution for fetching, but it restricts updating the FK field (
typeId
) because it is set up as a principal key. The "working" solution for fetching is below:Thank you in advance, I hope you have an idea on how to configure such a relation 🙏
The text was updated successfully, but these errors were encountered: