Print Page | Close Window

[SOLVED] Adding a New Entity with Params--The CAB Way

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=457
Printed Date: 11-Jun-2026 at 6:00pm


Topic: [SOLVED] Adding a New Entity with Params--The CAB Way
Posted By: Linguinut
Subject: [SOLVED] Adding a New Entity with Params--The CAB Way
Date Posted: 28-Sep-2007 at 5:00pm

I have the following code in my "old" model of the Contact entity:

public static ContactMaster Create
(
   
PersistenceManager pPersMgr,
   
int pSource,
   
int pMasterIndex,
   
int pAddressIndex,
   
string pLastName,
   
string pFirstName
)
{
    ContactMaster aContact = (ContactMaster)pPersMgr.CreateEntity(typeof(ContactMaster));
    aContact.AddToManager();
    aContact.Sourceindex = pSource;
    aContact.Masterindex = pMasterIndex;
    aContact.Addressindex = pAddressIndex;
    aContact.Lastname = pLastName;
    aContact.Firstname = pFirstName;
   
return aContact;
}

How would I make this call to the create method within the CAB?  At what point would that call happen?  I would think it would occur in the business module at some point.  If so, are there some overrides out there I should be taking advantage of?  Is there an entity creator service or something like that?

I am doing my own investigation, as always, but if anyone can point me in the right direction, then I won't have to retrace a lot of steps.
 
Thanks!
Bill



Replies:
Posted By: Linguinut
Date Posted: 29-Sep-2007 at 8:06am
Please note that I figured out how to do this within my own control view controller; however, I am not sure how to utilize the same behavior within a summary detail page, and such.  What should I override there in order to make it work?  I will look into this more next week.


Posted By: Linguinut
Date Posted: 01-Oct-2007 at 1:32pm
I discovered the following code in the CustomersPageController:
 
/// <summary>
/// Tell the BindingSource how to add new objects.
/// </summary>
/// <remarks>
/// A BindingSource has its own (peculiar) way of managing creation of new objects.
/// Could ignore it and use traditional methods but some controls (e.g., grids)
/// understand the BindingSource protocol and it conveniently adds the new
/// items to its list so we go with it here.
/// </remarks>
protected override void EnableMainBindingSourceAddNew()
{
    //MainBindingSource.AllowNew = CustomerMaster.EntityCreator.AllowCreate;
    //MainBindingSource.AddingNew += BindingSourceAddingNewHandler;
}
 
This seems like the place to go in order to employ the custom Create method of a specific entity.  Should I place my CustomerMaster.Create() call here, or is there another method that needs to be overridden for best results?
 
Thanks,
Bill
 


Posted By: Linguinut
Date Posted: 01-Oct-2007 at 2:32pm

Trial and error is a wonderful thing...just really time-consuming!

Here is the solution to my adding a new entity the CAB way--override the CreateEntity method in the page controller, like this:
protected override CustomerMaster CreateEntity(System.ComponentModel.AddingNewEventArgs pArgs)
{
    return CustomerMaster.Create(EntityManager.PersistenceManager, "[CUSTOMER NAME]", 1); ;
}
 
This works like a charm (even when using the PooledNumericIdGenerator!!!).



Print Page | Close Window