How to dynamically create db tables with code first in the prism wpf modular application?

I use a prism to create a modular application with plug-ins.

I have already configured sqlite with EF in a separate project, which will be included in each module.

BUT

I want my module to have a Model folder with the classes that are needed only by it, so that when loading the wpf shell, the system will create db tables for it (if they do not already exist).

How can I “inject” model classes into a class DbContextat runtime, for example, when I register views and view modes with a UnityContainer?

+4
source share
2

EF 6, modelBuilder.RegisterEntityType(type); , . modelBuilder.Configurations.AddFromAssembly();, Entity . , -. - , (BTW, ), .

0

T4 ( ) - , DbContext Model.

, :

https://www.paragon-inc.com/resources/blogs-posts/using-t4-to-generate-a-dbcontext-in-code-first

"" DbContext runtime, , UnityContainer?

T4 , DbContext DbSets (Model):

apporach DbConext "" () .

1) T4 DbContext

2) ( , DbSets 3)

3) T4 DbSets ( 2) DbContext

[]
DbContext T4, .

https://github.com/coni2k/DbContextGeneratorWithCodeFirst

+1

Source: https://habr.com/ru/post/1648004/


All Articles