If I were to include a review of LINQPad, it would be but I don’t want to consume this post on that, however in case you do not know what LINQPad is, for the purpose of this article, it allows us to write LINQ to SQL statements along with any other arbitrary C# code (basically just a disclaimer that you will not see any Data Context creation/code in my samples since it is implicit in LINQPad).
We will be using the same console application that we created in the previous article, so make sure you have read the previous article before we continue.
We will be adding three methods to the console application: add Customer(), delete Customer() and modify Customer() Create and Add Objects in Entity Framework 4.0 In order to add new objects to the Entity Set, you must create an instance of an Entity type and add the object to the object context.
Since I recently converted my site to blogengine.net, I’ll use its database schema for all examples to follow.
In addition to this, all code snippets you’ll see were run in LINQPad, which at the moment is by far my favorite development tool that I’m using (now if they’d only get intellisense in there, I’d play with this program all day long).
Here are some of the problems that you have to solve: 1) How can you create these web services without having to create a separate set of entity objects (that is, we want to use the entity objects that the LINQ to SQL designer generates for us)?
2) What do we have to do to get LINQ to SQL to work with entities passed in through web services?3) How do you create these loading/saving web services while keeping the amount of data passed across the wire to a minimum?I created a sample project using the Northwind sample database.A couple weeks ago, I read the article, LINQ to SQL Extension: Batch Deletion with Lambda Expression by Jeffrey Zhao.In case you didn’t read the article, it discusses the downside of most O/R Mapping frameworks when it comes to multiple updates or deletes.Objects attached to the object context are managed by that object context. Observe the code shown below: All we are doing here is create a new instance of the Customer type and populate its properties.