Nuestro buen amigo JC Olamendy ha escrito un interesante artículo, aquí los detalle:
I’ve been searching in Internet for articles about Linq to SQL and most of the articles are written for connected environments where we have a data context created and the database operations are executed in the data context, but there are common business scenario where we gather data from a context and we move to another context to update the changes to the database such as ASP.NET Web applications and data transfer using Web services as well as desktop applications when we separate the data access code from the business logic code. In this example, I will show how to execute Crud operations using Linq to SQL in a disconnected environment where we use different data contexts to execute different operations. Our application is a classic multi-layer application where we separate the objects in layers according to the functions in the application. In order to simplify the logic, we are going to build a desktop application with only two layers: one for the presentation of the data and the other one for implementing the data access logic.
Getting started with the solution
Let’s open the Visual Studio.NET 2008 IDE and create a Windows Forms Application project. We’re going to create a desktop application which connects to a SQL Server 2005 database system and manages the data on the dbo.Department table on a TestDB database. The schema of the dbo.Department table is show in the Listing 1.
CREATE TABLE [dbo].[Department]
[DeptID] [int] NOT NULL,
[DeptName] [varchar](50) NOT NULL,
[Location] [varchar](50) NOT NULL,
CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
Then add a new form for the management of the Department entities in the database and add three label controls, three textbox controls, and four button controls in order to get a GUI as shown in the Figure 1.
Next step is to add a new “Linq to SQL Classes” artifact to implement the data access logic through “Linq to SQL” mechanism (see Figure 2).
ver el articulo completo aqui.
Fernando García Loera (Community Program Manager – Latin America Region)
Que es un MVP? Tips para ser MVP