AspNetCoreLocalization icon indicating copy to clipboard operation
AspNetCoreLocalization copied to clipboard

Working with LocalizationModelContext

Open inexuscore opened this issue 8 years ago • 4 comments

Hi again @damienbod I'm curious, how would I work with the underlying DbContext in my app? Suppose I want to seed localization data at Startup (populating the LocalizationRecords table). Or maybe I want to create a web console in my app, where I can query the records, do CRUD operations etc.

Thanks in advance :sun_with_face:

inexuscore avatar Jun 12 '16 08:06 inexuscore

Hi @inexuscore

Seed should be possible as you have the DbContext in your project. If changes are required to the DbContext itself, then I would use the Localization.SqlLocalizer directly instead of the NuGet package and change it. We could then add this to the package if it helps others.

https://github.com/damienbod/AspNet5Localization/tree/master/AspNet5Localization/src/Localization.SqlLocalizer

Here's the context https://github.com/damienbod/AspNet5Localization/blob/master/AspNet5Localization/src/Localization.SqlLocalizer/DbStringLocalizer/LocalizationModelContext.cs

Greetings Damien

damienbod avatar Jun 12 '16 08:06 damienbod

Hi @damienbod Great, I think I'll pull in the source to my project and have it as another layer. The DbContext doesn't require any changes, at least not now, not that I can think of any. But there's only one change I would make: configuring a default value for the UpdatedTimestamp column. That way we'll be able to manually add records in SSMS, Visual Studio or other clients.

Thanks for the repo!

inexuscore avatar Jun 12 '16 09:06 inexuscore

I'll add an interface for the LocalizationModelContext : ILocalizationModelContext Then you can write your own if required, for example configuring a default value for the UpdatedTimestamp column

damienbod avatar May 11 '17 07:05 damienbod

interface won't work, need to think of a better solution.

damienbod avatar May 11 '17 07:05 damienbod