Print Page | Close Window

removing a dynamic type?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=373
Printed Date: 12-Jun-2026 at 12:17am


Topic: removing a dynamic type?
Posted By: labcede
Subject: removing a dynamic type?
Date Posted: 16-Aug-2007 at 11:40am
Is it possible to remove a dynamic type from memory (so that i can redefine it)?

I have DataTable "X" w/ 3 columns used for the EntityTypeInfo for a dynamic type w/ the key equal to "DTR."  I modify table "X" and now it has 4 columns.  I'd like to redfine my Dynamic Type "DTR" so that the EntityTypeInfo reflects these changes.



Replies:
Posted By: Linguinut
Date Posted: 16-Aug-2007 at 12:19pm

This is just a guess...try removing it from the PersistenceManager (including query cache).  RemoveEntity, maybe?  This is a good question.

Btw, it sounds like you may be utilizing datagridviews to present your data...are you using a datagridviewbindingmanager to bind the dynamic entity to the grid?  If so, how are you doing it?
 
Thanks!
Bill


Posted By: labcede
Date Posted: 16-Aug-2007 at 12:39pm
RemoveEntity does not remove the type in memory.

Yes, I'm using the datagridviewbindingmanager ... I've done 2 separate test with both the Designer and at run-time without problems.


Posted By: Linguinut
Date Posted: 16-Aug-2007 at 1:53pm

The key to manipulating the DGVBM in code is to add a ViewDescriptor (IdeaBlade) to the Descriptiors collection...not a DataGridViewBindingDescriptor (DotNetControl).  Hopefully, IdeaBlade will include an example of this in their next release of the tutorial solution.  I have an example if anyone is interested.

Is it possible to set the type to null?  I will try this and let you know if it works.
 
Bill


Posted By: Linguinut
Date Posted: 16-Aug-2007 at 1:56pm
Nope, null does not work.  The key still exists.  It must be in the PM somewhere.


Posted By: kimj
Date Posted: 16-Aug-2007 at 4:01pm

The Type itself that you've created cannot be removed from memory (or really more correctly from the AppDomain), but you can, in some situations, modify the columns of the corresponding EntityTable.

If you didn't define a primary key when creating the type, the actual EntityTable managed by the PM will always be recreated based on the latest query for the dynamic type.
 
If you did define a primary key, you can possibly still modify the EntityTable without harm, but it does require some care.  How you do this modification may also depend on how you created the type, but here's one way:
 
// Get the table out of the PM
EntityTable tbl = mPm.GetTable(myDynamicEntityType);
// Modify the table
tbl.Columns.Add("NewIntCol", typeof(int));
//Optionally reset the prototype table
EntityTypeInfo.SetPrototypeTable(tbl, "");
You do this at your own risk, and it's doubtful that persistence operations on the type would work, but I haven't tried.  If you're using a BOS you might also run into trouble with the schemas being out of sync between the client and server, but again I have tried it out. 


Posted By: labcede
Date Posted: 17-Aug-2007 at 5:58am
great!  that worked.  i'm not really considered with keeping the schemas in sync with the persistence server.  my dynamic entity is only used locally and not for any data persistence.

thanks!



Print Page | Close Window