C#添加表< T>到现有的DataContext实例 [英] C# add a Table<T> into an existing DataContext Instance

查看:365
本文介绍了C#添加表< T>到现有的DataContext实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家
是有可能,我可以添加表< T> dynamiclly到exisitng的DataContext Insance在LinqToSQL

Guys Is it possible that I can add Table<T> dynamiclly to an exisitng DataContext Insance in LinqToSQL?

下面是我的情况:
我有几个classsed其中使用[测试]属性来声明为表,我想允许用户创建在运行时相应的SQL Server表。我明白,如果我继承DataContext类,我可以添加成员
表的客户;在类
,它会在全自动后端数据库创建这样一个表。
然而,问题是,我是否可以在运行时一个DataContext类帮助我创建对应于T中的correspondgin SQL Server表中添加表。

Here is my case: I have several classsed which are using [Test] attribute to declared as Table, I want to allow user to create the corresponding SQL Server tables during run-time. I understand that If I inherit the DataContext class, I can add member Table customers; in the class and it will automaticly create such a table at the backend database. However, the problem is that whether I can add Table during run-time to a DataContext class which help me to create the correspondgin SQL Server Table corresponding to T.

推荐答案

我不认为这是可能的。 LINQ2SQL从属性读取元信息,并把它们存储在缓存中 - 对上下文的所有实例

I don't think that this is possible. Linq2Sql reads Meta information from your Attributes and store them in a cache - for all instances of your context.

您唯一的机会是在内存中生成的类,然后发射他们入的新的的AppDomain中。听起来很难,但事实并非如此。但你要如何访问这些类?反射?

The only chance you have is to generate those classes in Memory and then emit them into a new AppDomain. Sounds hard, but it isn't. But how do you want to access those classes? Reflection?

这篇关于C#添加表&LT; T&GT;到现有的DataContext实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆