0

After trying this kind of things: How to add property-level Attribute to map ColumnAttribute at runtime? I've find another problem.

The reason it's because I want to reuse the same instance of DataContext. But when I want to refresh DataContext after changes then I get ArgumentException 'An element with the same key is already added'. I've tried this so far:

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
Community
  • 1
  • 1
lorddarkangel
  • 212
  • 3
  • 21
  • It is not clear to me what you're trying to do and why. But reusing context instances is nearly always a bad idea. Also, changing the context by hacking your way into it may cause all kinds of side effects you can't possibly fathom. Stick to the public API. If it doesn't offer what you want you probably shouldn't want it or you must try to achieve it in a more elaborate, but intended way. – Gert Arnold Jun 27 '13 at 15:05
  • I'm trying to add a new column to a table in an existing schema. But I have to do it in runtime. – lorddarkangel Jun 28 '13 at 07:38

0 Answers0