Updating data linq
We can do this by adding partial classes to our project that add validation rules to our data model classes (I cover how to-do this in-depth in my Part 4: Updating our Database LINQ to SQL tutorial).For example, we could add validation rules to enforce that the Customer's phone number follows a valid phone pattern, and that we don't add Orders where the customer's Required Date for delivery is before the actual Order Date of the Order.If you are still reading this, you might be feeling confused about where SPROCs fit into this post.Why did I show you above how to write code that works with our data model objects, and then causes dynamic SQL to run?For example, we could add a helper method called "Get Customer()" that enables us to lookup and retrieve a Customer object from the database based on their Customer ID value: We now have a data access layer that encapsulates our data model, integrates business validation rules, and enables us to query, update, insert, and delete the data.Let's look at a simple scenario using it where we retrieve an existing customer object, update the customer's Contact Name and Phone Number, and then create a new Order object and associate it with them.
Additional Info: Class Structure is : Public Class Contact Con Property Con Id As String Property Con Row ID As String Property Title As String Property Mob1 As String Property Mob2 As String Property Land1 As String Property Land2 As String Property Email1 As String Property Email2 As String Property Fax1 As String Property Fax2 As String Property Primary As Boolean Public Sub New() Con Id = "" Con Row ID = "" Title = "Contact1" Mob1 = "" Mob2 = "" Land1 = "" Land2 = "" Email1 = "" Email2 = "" Fax1 = "" Fax2 = "" Primary = False End Sub End Class LINQ stands for Language Integrated Query.
NET Framework 3.5 release, and which enables you to model relational databases using . You can use LINQ expressions to query the database with them, as well as update/insert/delete data.
Below are the first six parts in this series: In part 6 I demonstrated how you can optionally use database stored procedures (SPROCs) and user defined functions (UDFs) to query and retrieve data using your LINQ to SQL data model.
We can do this by writing LINQ expressions against our data model classes to query the database and populate them (I cover how to-do this in my Part 3: Querying our Database LINQ to SQL tutorial).
Alternatively we could map SPROCs to our Data Context and use them to populate the data model classes (I cover how to-do this in my Part 6: Retrieving Data using Stored Procedures LINQ to SQL tutorial).
Refresh() method calls before submitting the changes solved the problem and the values are updated in the database tables properly.