New Posts New Posts RSS Feed: Looping through a dynamic entity type
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Looping through a dynamic entity type

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: Looping through a dynamic entity type
    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);

}

}

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: 17-May-2010 at 10:38am
Look at the following advanced tutorial:

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.
Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post 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();
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: 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();

}

Back to Top
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post 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.
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down