This is a migrated thread and some comments may be shown as answers.

update database values urgent

1 Answer 49 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Derya Altuntas
Top achievements
Rank 1
Derya Altuntas asked on 10 Nov 2009, 04:29 PM
Hi,
Platform configuration is a database class that has relationship with SensorRadar class.Combobox is loaded from SensorRadar Table.
I want to add new Sensor Radar to Platform Configuration if it doesn't.And change Sensor Radar with selected combobox Sensor Radar if it has .But Platform configuration object_id column doesn't change.It refers to SensorRadar class Id.Please help.How can update.

bool isPlatformHasRadarSensor = false;
                foreach (PlatformConfiguration platformConfiguration in m_originalMunitionList)
                {
                    
                    if (platformConfiguration.ConfigurationItemType == Constants.CONFIGURATION_ITEM_TYPE_SENSOR_RADAR)
                    {
                        platformConfiguration.SensorRadar = ((SensorRadar)m_cmbbx_loadAirRadar.SelectedItem);
                        isPlatformHasRadarSensor = true;
                        
                    }
                    
                }
                if (!isPlatformHasRadarSensor)
                {
                    IQuery query = m_scope.GetSqlQuery("sp_ins_Pltfrm_Conf ?,?,?,?",

                                            null,

                                    "GUID object_ID, GUID platform_ID, INTEGER configuration_item_type, INTEGER quantity");



                    IQueryResult a = query.Execute(new object[] { ((SensorRadar)m_cmbbx_loadAirRadar.SelectedItem).Id, selectedAirPlatform.Id, Constants.CONFIGURATION_ITEM_TYPE_SENSOR_RADAR, null });
                    int count = a.Count;
                }

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 11 Nov 2009, 03:50 PM
Hi Derya Altuntas,

In order to work with persistent data an object scope is required. The object scope provides a working area for all database objects. I assume that the m_originalMunitionList is a list of persistent objects, retrieved by executing a query against certain IObjectScope instance. You can use the following code to retrieve that IObjectScope:
IObjectScope scope = Database.GetContext(m_originalMunitionList) as IObjectScope;

Before you can perform any operations on the persistent objects, you need to start a transaction. This is done with the ITransaction.Begin() method. Any modifications made to an object after beginning the transaction can be stored in the database by calling ITransaction.Commit(). Performing the update operation inside the foreach loop would look like this:

if (platformConfiguration.ConfigurationItemType == Constants.CONFIGURATION_ITEM_TYPE_SENSOR_RADAR)
{
      scope.Transaction.Begin();
    platformConfiguration.SensorRadar = ((SensorRadar)m_cmbbx_loadAirRadar.SelectedItem);
scope.Transaction.Commit();
    isPlatformHasRadarSensor = true;
}
You can begin and commit the transaction outside of the loop as well.

Additional useful information about the CRUD operations and Telerik OpenAccess ORM could be found in this article. Hope that helps.

Regards,
Damyan Bogoev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Databases and Data Types
Asked by
Derya Altuntas
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or