Update an entity with composite primary key

Posts   
 
    
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 26-Jul-2009 18:50:36   

Greetings,

I have an entity that mapped to sql view "CustomerData" it isn't updatable

In UI the user can edit and change his data

In BL =>I collect the new edited date from user and crate a new entity that mapped to sql table (this table has 3 fields considered as composite primary key) => turn IsNew property to false =>but i missing to force the dbValue to this entity

How can force the DBValue to an entity ???

llblgen version 2.6 adapter mode Sql2008 V.S 2008 C#

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Jul-2009 10:31:54   

=>but i missing to force the dbValue to this entity

How can force the DBValue to an entity ???

Why do you want to force a value for the DBValue? Please post a code snippet, of what you are trying to do. Thanks.

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 27-Jul-2009 12:27:55   

Walaa wrote:

Please post a code snippet, of what you are trying to do. Thanks.

foreach (VnCustomerEntity item in superitem.VnCustomerCollection)
                {
                    CustomerEntity customerEn= new CustomerEntity();

                    customerEn.GroupID = superitem.GroupID;
                    customerEn.LnNo = superitem.LnNo;
                    customerEn.AccountID = item.AccountID;
                    customerEn.Broker = item.Broker;
                    customerEn.Serial = ++j;
                    customerEn.StockCenter = item.StockCenter;
                    customerEn.TradingNo = item.TradingNo;
                    customerEn.IsNew = item.IsNew;
                    customerEn.StartDate = item.StartDate;
                    customerEn.EndDate = item.EndDate;
                    customerEn.ManuallySelected = item.ManuallySelected;
                    customerEn.EntryDate = DateTime.Now;
                    customerEn.UserId = Utils.UserName;
                    customerEn.TerminalId = Utils.ComputerName;

                    DataBase.Save(customerEn);
               }

if IsNew= false the update condition statment (Where clause) it takes the new value like


Where GroupID = 1  -- as this value will changed from 5 to 1

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Jul-2009 15:01:30   

if IsNew= false the update condition statment (Where clause) it takes the new value like Code:

Where GroupID = 1 -- as this value will changed from 5 to 1

Most probably I'm missing something obvious, but still I can't see why DBValue is needed here.

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 27-Jul-2009 15:36:08   

Ok.. Let's clear it first of all, When I create new entity and switch its IsNew property to false,What is behaver for save(Update) i think.. it's update the record in DataBase where primary = primary value. it's right..?!

Second If this entity contain more than one field that considered as primary key (composite primary key) But in this case i change the value of one from composite primary key,false,What is behaver for save(Update)

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Jul-2009 16:17:48   

Ok.. Let's clear it first of all, When I create new entity and switch its IsNew property to false,What is behaver for save(Update) i think.. it's update the record in DataBase where primary = primary value. it's right..?!

Correct.

Second If this entity contain more than one field that considered as primary key (composite primary key) But in this case i change the value of one from composite primary key,false,What is behaver for save(Update)

I think you want to change the currentValue of the PK field, not the DBValue, so you should be using ForceCurrentValueWrite(), please look it up in the reference manual.

Side notes: 1- Are you sure that when you change a value of the PK fields, the resultant composite PK values will always match a record in the database? 2- Just in the case of an Update, you may use adapter.UpdateEntitiesDirectly(), to pass a filter based on which the entity should be updated, instead of using adapter.SaveEntity().