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); } } asp.net版本设置成2.0.50727之后asp无法运行 如何在win2003服务器里设置asp.net环境,发布asp.net网站??谢谢 js绑定下拉列表 鼎鼎条码批量打印系统是如何实现的? 有没有什么办法把某个文件夹下的文件名自动存入数据库???? 请教一个小问题 只剩下10分了 请务必帮忙啊! forms验证问题! javascript中有menubar,tree对象吗 session的timeout时间比设置的少的多,为什么? 同志们,我又遇到问题了!我的image控件不刷新!!! 页面的数据以图片显示,防抓取 依据目录分割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);
}
}