New Posts New Posts RSS Feed: Setting Primay Key values
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Setting Primay Key values

 Post Reply Post Reply
Author
downeytim View Drop Down
Newbie
Newbie


Joined: 08-Dec-2009
Location: Dallas, Texas
Posts: 18
Post Options Post Options   Quote downeytim Quote  Post ReplyReply Direct Link To This Post Topic: Setting Primay Key values
    Posted: 15-Dec-2009 at 11:26am
The object mapper by default sets all PK fields to ReadOnly.
 
In many cases in our application we are passing the values for the PK to the create method on a Business Object class.
 
In the example below ComponentId is the PK of IOComponentOption.  How do I set this without changing all the field definitions in the Object Mapper for 500+ business objects?  I assume I can use the SetColumnValue method but this is a lot of code to rewrite for almost every business object.
 
EXAMPLE:
 

public static IOComponentOption Create(int componentId){

   IOComponentOption option = Session.PM.CreateEntity<IOComponentOption>() as IOComponentOption;

   option.ComponentId = componentId;

   option.Data = String.Empty;

   option.AddToManager();

   return(option);

}

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: 15-Dec-2009 at 1:59pm

I am not completely sure what you are trying to do, but you may find this trick helpful.  Assume emp is an Employe

emp.id = 22
 
gives compiler error.  "Property Id is read-only";
 
but
 
emp["Id"] = 22;
 
compiles and assigns 22 to Id property;
 
You can also use:
 
emp[0] = 22;
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down