AspNetCoreContentLocalization
AspNetCoreContentLocalization copied to clipboard
There's no way to specify individual length for specifiv entities values
Hello Dmitry, thanks for your nice work, but once I started implementing it, I thought about is there a way to specify individual length per each entity ? e.g. for Name: Varchar(200). and for Description: Varchar(400) ? seems like all they rely on Localization.Value , which is Varcharmax though.
@DmitrySikorsky As I need to implement this on my project quickly, I decided to go with next solution, please let me know what do you think :)
So, I'm gonna make classes Localization and LocalizationSet as abstract, and have sepaerate implementations for each size e.g.
class Localization_300 : Localization {}
and then
class LocalizationSet_300:LocalizationSet
{
public virtual ICollection<Localization_300> Localizations { get; set; }
}
and on modelbuilder we gonna have
builder.Entity<LocalizationSet_300>(etb =>
{
etb.HasKey(e => e.Id);
etb.ToTable($"LocalizationSets_300_${tenantName}");
}
);
builder.Entity<Localization_300>(etb =>
{
etb.HasKey(e => new { e.LocalizationSetId, e.CultureCode });
etb.Property(x => x.Value).HasMaxLength(300);
etb.ToTable($"Localizations_300_${tenantName}");
}
);
So that way I'm gonna have separate static support for each value length e.g. for Book Entity I can have
class Book
{
public int Id { get; set; }
public int NameId { get; set; }
public int DescriptionId { get; set; }
public int AuthorId { get; set; }
public int Year { get; set; }
**public virtual LocalizationSet_300 Name { get; set; }
public virtual LocalizationSet_1000 Description { get; set; }
public virtual LocalizationSet_50 Author { get; set; }**
}
The think that, they're gonna be split into multiple tables, but anyway it is good for performance, they have less memory size instead ov varchar max, and split table also another performance boost.
Hi Hakob, yes, you are right, there is no limits on entity level, but you still can use MaxLength data annotation attribute to validate text length on server side. If it is important to control text length on database level either, the solution you described will work.
@DmitrySikorsky Thanks for your reply, yes, it is important, as having very huge localizations table is not gonna work for us. And also yesterday I came up with better solution. I removed Localization and LocalizationSet entities, kept only Culture entity. Then created BookTranslation entity, where I moved Translatable entities, and created one to many relationship with the Book entity.