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

Update schema, default value for a new column

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 23 Sep 2014, 12:44 PM
Hi,

I use telerik Version 2011.1.411.2 (Runtime 2.0.50727).

I added a new colum in my database schema (for information double d_Value),
and I want that the data that is already memorized in database take value "1.0" not "0.0".

Can you explain how can I do ?

In advance, Thanks,
Richard.

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 26 Sep 2014, 07:52 AM
Hi Richard,

You can achieve the necessary result in one of the following ways:

1. Update Telerik Data Access to the latest version, update your model with the latest changes in the database, and in your code use the bulk update feature as demonstrated here. This way all the necessary changes will be performed on the server side, without any need for you to write SQL statements or load all the objects in memory before updating them.

2. Execute a query similar to the one demonstrated below in SQL Server Management Studio:
USE [MyDatabase]
GO
 
UPDATE [MySchema].[MyTable] 
SET d_Value = 1.0
FROM [dbo].[Order Details]
WHERE d_Value = 0.0
This way all the values will be updated with a single statement.

3. With your current version, update your model to the latest state of the database, and execute code similar to the demonstrated below in an application that consumes the model:
using (EntitiesModel dbContext = new EntitiesModel())
{
    foreach (var item in dbContext.OrderDetails.ToList())
    {
        item.D_Value = 1;
    }
 
    dbContext.SaveChanges();
}
Note that this is not recommended, because all the objects will be loaded in memory prior to the update.

I hope this helps. If you need further information, do not hesitate to get back to us.


Regards,
Doroteya
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Richard
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or