Print Page | Close Window

Check existence of dynamic entity

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=243
Printed Date: 12-Jun-2026 at 12:10am


Topic: Check existence of dynamic entity
Posted By: naveen.menon
Subject: Check existence of dynamic entity
Date 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.



Replies:
Posted By: davidklitzke
Date 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.

 


Posted By: kimj
Date 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
 
}



Print Page | Close Window