entity 如何为dbcontext运行时动态附加上一个dbset entitymvcdbcontext 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考Creating DbSet Properties DynamicallyDbSet<MyEntity> set = context.Set<MyEntity>();或DbSet set = context.Set( typeof( MyEntity ) );或者利用反射,通过实现DbContext的OnModelCreating方法,参考Dynamically Adding DbSet Properties in DbContext for Entity Framework Code Firstpublic class MyAppContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { CustomAssemblySection configSection = (CustomAssemblySection)System.Configuration.ConfigurationManager.GetSection("CustomAssemblySection"); foreach (CustomAssembly customAssembly in configSection.Assemblies) { Assembly assembly = Assembly.Load(customAssembly.Name); foreach (Type type in assembly.ExportedTypes) { if (type.IsClass) { MethodInfo method = modelBuilder.GetType().GetMethod("Entity"); method = method.MakeGenericMethod(new Type[] { type }); method.Invoke(modelBuilder, null); } } } base.OnModelCreating(modelBuilder); } } 向数据库中插入信息问 如何在应用了母版页的aspx页面添加scriptmanager 求一个正则表达式 新年快乐,高手请进,求一SQL语句 往SQL数据库中写入数据不支持中文 菜鸟问个asp.net操作sql输出xml语句的问题 asp.net 在线等。。。。能不能把DataGrid绑定列的值 用数组元素付。 新开发一OA,用Asp.NET,如何与Asp共存及通信 怎样将null插入到数据库? 页面的数据以图片显示,防抓取 依据目录分割word文档
Creating DbSet Properties DynamicallyDbSet<MyEntity> set = context.Set<MyEntity>();或DbSet set = context.Set( typeof( MyEntity ) );或者利用反射,通过实现DbContext的OnModelCreating方法,参考
Dynamically Adding DbSet Properties in DbContext for Entity Framework Code Firstpublic class MyAppContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
CustomAssemblySection configSection = (CustomAssemblySection)System.Configuration.ConfigurationManager.GetSection("CustomAssemblySection");
foreach (CustomAssembly customAssembly in configSection.Assemblies)
{
Assembly assembly = Assembly.Load(customAssembly.Name);
foreach (Type type in assembly.ExportedTypes)
{
if (type.IsClass)
{
MethodInfo method = modelBuilder.GetType().GetMethod("Entity");
method = method.MakeGenericMethod(new Type[] { type });
method.Invoke(modelBuilder, null);
}
}
}
base.OnModelCreating(modelBuilder);
}
}