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 must shout out to ef core team, and arthur. you guys doing splendid job.
I am experimenting to implement internationalization with the help of ef core. currently each entity has a List of another object which holds the translatable properties. example code
public class Language
{
public int Id { get; set; }
public int Name { get; set; }
}
public class Employe
{
private readonly Language _language;
public Employe(string name, double salary, Language language)
{
Translations = new List<EmployeTranslation>();
Salary = salary;
UpdateName(name, language);
}
private Employe(Language language)
{
_language = language;
}
public int Id { get; set; }
public double Salary { get; set; }
public string Name => Translations.FirstOrDefault(e => e.Language.Equals(_language))?.Name;
public ICollection<EmployeTranslation> Translations { get; set; }
public void UpdateName(string newName, Language language)
{
var existingLanguageTranslation = Translations.FirstOrDefault(e => e.Language.Equals(language));
if (!(existingLanguageTranslation is null))
Translations.Remove(existingLanguageTranslation);
Translations.Add(new EmployeTranslation(language, newName));
}
}
public class EmployeTranslation
{
public EmployeTranslation(Language language, string name)
{
Language = language;
Name = name;
}
public Language Language { get; set; }
public string Name { get; set; }
}
I would like ef core to inject a runtime Language object or even an int LanguageId when constructing several entity types via the private constructor. in Entity types with constructors documentation it clearly says
Currently, only services known by EF Core can be injected. Support for injecting application services is being considered for a future release.
but that was 3 years ago. is it possible for ef core 3.1? or even ef core 5?
currently im using a global filter on Translation entities to filter for a current request language as a workaround. or perhaps as long lasting solution.
The text was updated successfully, but these errors were encountered:
I must shout out to ef core team, and arthur. you guys doing splendid job.
I am experimenting to implement internationalization with the help of
ef core
. currently each entity has a List of another object which holds the translatable properties. example codeI would like
ef core
to inject a runtimeLanguage
object or even anint LanguageId
when constructing several entity types via the private constructor. in Entity types with constructors documentation it clearly saysbut that was 3 years ago. is it possible for
ef core 3.1
? or evenef core 5
?currently im using a global filter on
Translation
entities to filter for acurrent request language
as a workaround. or perhaps as long lasting solution.The text was updated successfully, but these errors were encountered: