如何使用相同的DataContext实例修改Linq to Sql映射?

时间:2013-06-27 12:43:31

标签: linq-to-sql datamapper

尝试过这类事后:How to add property-level Attribute to map ColumnAttribute at runtime?我发现了另一个问题。

之所以会这样,是因为我想重用同一个DataContext实例。但是当我想在更改后刷新DataContext然后我得到ArgumentException'已经添加了具有相同键的元素'。 到目前为止我已经尝试过了:

FieldInfo field = DataContext.Mapping.GetType().GetField("metaTables", BindingFlags.NonPublic | BindingFlags.Instance);
Dictionary<Type, MetaTable> metaModels = field.GetValue(DataContext.Mapping) as Dictionary<Type, MetaTable>;

metaModels.Remove(typeof(MyClass)); //Remove the class that I've modified

DataContext.Mapping.GetTable(typeof(MyClass)); //ArgumentException

0 个答案:

没有答案