New Posts New Posts RSS Feed: Check existence of dynamic entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Check existence of dynamic entity

 Post Reply Post Reply
Author
naveen.menon View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Jul-2007
Location: United States
Posts: 5
Post Options Post Options   Quote naveen.menon Quote  Post ReplyReply Direct Link To This Post Topic: Check existence of dynamic entity
    Posted: 12-Jul-2007 at 7:57pm

How do we check for the existence of an dynamic entity prior to creating a new one?

For e.g, I create such an entity, as below.
 

DynamicEntityTypeBuilder.CreateType("ProjectTypeCount", "Default")

If this line executes a second time, I get a message that says "Entity already exists".
 
How can I query the persistence manager to check if this entity already exists ?
 
Thanks.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 31-Jul-2007 at 2:57pm
Naveen,
 

You can use EntityTypeInfo.GetAllDynamicTypes()to iterate through all of the types in the PersistenceManager cache.  Try something like this

 

      foreach (EntityTypeInfo eti in EntityTypeInfo.GetAllDynamicTypes()) {

        if (typeof(DynamicEntity).IsAssignableFrom(eti.EntityType) && (eti.DataSourceExtension == this.mPm1.DataSourceExtension)) {

          /// Add code to compare Entity types

                }

      }

 

Note that the EntityTypeInfoGetAllDynamicTypes method is unfortunately misnamed – it will return all known entity types, and also returns everything for all known data source extensions.  (We might enter a defect report to fix this.)  Anyway, if you then filter out actual dynamic types for your data source extension, you can then compare the dynamic type that you found with the dynamic type that you would like to create.

 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 02-Aug-2007 at 4:30pm
If you already know the "dynamic type key name" then you can also look for it directly, like this:
 
EntityTypeInfo info = EntityTypeInfo.GetByDynamicTypeKey("ProjectTypeCount");

if (info == null) {

   // Create dynamic type
 
}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down