Print Page | Close Window

Looping through a dynamic entity 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=1817
Printed Date: 28-Apr-2025 at 4:24am


Topic: Looping through a dynamic entity type
Posted By: BillG
Subject: Looping through a dynamic entity type
Date Posted: 16-May-2010 at 10:19am
I have created the following dynamic entity type. How do I now loop through the entity type looking at all the ssns and using them.

DataTable aTable = new DataTable();

aTable.Columns.Add("MDID", typeof(Int32));

aTable.Columns.Add("SSN", typeof(String));

aTable.PrimaryKey = new DataColumn[] { aTable.Columns["MDID"] };

Type aDynamicType = DynamicEntityTypeBuilder.CreateType("foo", "Default", aTable);

Entity aDynamicEntity;

foreach (DuesPaid dp in currentBatch.DuesPaids)

{

try

{

aDynamicEntity = myPM.CreateEntity(aDynamicType);

aDynamicEntity.ItemArray = new Object[] { dp.Mdid, dp.SocSecNo };

aDynamicEntity.AddToManager();

}

catch (Exception ex)

{

throw new Exception(ex.Message);

}

}




Replies:
Posted By: davidklitzke
Date Posted: 17-May-2010 at 10:38am
Look at the following advanced tutorial:

file:///C:/Program%20Files/DevForce%20Classic/Instructional%20Units/300%20Advanced/Dynamic%20Entities - 336. Dynamic Entities

With DevForce Dynamic Entities, you can build runtime entities that include any subset of a table's columns, or even have properties for aggregate statistics. You can also create entities based on tables that didn't exist in the datasource at design time. Learn how!

This tutorial creates a dynamic type and then loops through all of the columns in the dynamic type.


Posted By: BillG
Date Posted: 17-May-2010 at 10:57am

 
I tried the following like the example in the word document in that tutoria and I get an error using IList
 
Non-Generic Type IList cannot be used with type arguments
 
DuesCalculator dc = new DuesCalculator();
IList<DynamicEntity> entities = myPM.GetEntities<Entity>(QueryStrategy.CacheOnly);  Error message on this line.
foreach (Entity e in entities)
{
     Int32 mdid = (Int32)e["MDID"];
     string ssn = (String)e["SocSecNo"];
     DeleteDuesAssessed(mdid, ssn);
     dc.CalculateOwing(ssn);
}
myPM.SaveChanges();
currentBatch.Status = "V";
SaveBatch();


Posted By: davidklitzke
Date Posted: 17-May-2010 at 11:58am
Look at the examples again.  They do not use an IList.  For example. here is a code fragment:
 

private void CreateDynEntyReadOnlyNoPk() {

Type aType = DynamicEntityTypeBuilder.CreateType("EmployeeLiteByRetrievalNoPk", "Default");

IEntityQuery anEntityQuery = new PassthruRdbQuery(aType, "Select Id, LastName, FirstName, BirthDate, City from Employee");

mEmployeeLites.ReplaceRange(mPersMgr.GetEntities<DynamicEntity>(anEntityQuery));

CreateDynamicProperties(aType);

BindToDynamicProperties();

}



Posted By: BillG
Date Posted: 17-May-2010 at 12:29pm
That does not seem to be what I want. Maybe I am using it wrong. What I want to do is to retrieve 2 fields out of the child record (Dues Paid). The fields are MDID and SSN. I want to delete the child records and then recalculate the members balances after the records are deleted.
 
I need to get the SSN out before I delete the record so that I know which member to recalculate
 
So I just want to temporarily hold the MDID and SSN field in a temporary storage place for multiple rows so that I can loop through the structure after the delete and recalculate balances.
 
 



Print Page | Close Window