Is that possible to create table in run time by using EF Code-first? i could create my models class in run time by using C# CodeDOM(reflection) but i couldn't set the dbSet properties of my Dbcontext class in run time. whats your idea? whats the best solution to create table dynamically in run time?... some ones said to my that the only way is using classic ADO.Net.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Yes,you can do that.
You can do that using Finding the Classes :
Now you can add some logic to the
OnModelCreating
method of yourcontext
to scan assemblies and add any classes with the[Persist]
attribute as shown below.You can use below mentioned code based data migration method hence automatically change the database when new classes or properties are added to the model.
You can read more about this : Dynamically Building A Model With Code First
Update : How to Query a Dynamic Table ?
See this for more : Querying data using Entity Framework from dynamically created table
finally to have a query on a dbContext which doesn't have any DbSet<>...
using this:
it's perfectly working if type and name of your model classes be much as like their related Tables name on database.(it has to be)
special Tnx for @Sampath