Current area: HOME -> Blogs -> DLinq

Blog Posts Tagged With DLinq

Very Quick Guide To DLinq: Part 3 (LIKE, IN, DATEDIFF)
Posted on Wednesday, April 30, 2008 at 6:50 AM
Much of the time, it's fairly straightforward to express an SQL query in Linq instead. However, there are some things that aren't quite so clear how to do. In this article, I'll take a look at some of those.

LIKE

There are a couple of ways to replace LIKE. If you just want to directly use LIKE, then you can do so using the SqlMethods class. To use this, you must add the following using declaration at the top of the file:
using System.Data.Linq.SqlClient;
Then we can use it like this:
var Result = from Book in DB.BookResources
             where SqlMethods.Like(Book.Title, "%java%")
             select Book;
This will create an SQL query that locates all books containing "java" (case-insensitively). Interestingly, you can also do the following:
var Result = from Book in DB.BookResources
             where Book.Title.Contains("java")
             select Book;


Read More
Tags: .NET, C#, DLinq

Very Quick Guide To DLinq: Part 2
Posted on Tuesday, March 25, 2008 at 2:45 AM
In this part I'm going to take a look at inserts, updates and deletes using DLinq.

The Overall Model

First, to make changes to a database, you instantiate the data context object, just as we did before doing selections in the previous part.
var DB = new ResourcesDB();
You then do the required changes; we'll look at this part in just a moment. However, the inserts, updates and deletions are not performed immediately. They do not take place until you explicitly submit the changes:
DB.SubmitChanges();
This means that you can make many changes, then send them to the database all at once.

Inserting Data Into A Table

To make a single new entry to a database table, use the InsertOnSubmit method on the Table object. This takes a single parameter: an instance of the object that represents a row in the the table. You can use the object initializer syntax to write this very neatly.
DB.BookResources.InsertOnSubmit(new BookResource()
{
Read More
Tags: .NET, C#, DLinq

Very Quick Guide To DLinq: Part 1
Posted on Friday, March 14, 2008 at 9:10 AM
We have already written about using Linq, but didn't cover DLinq. This post takes a quick look at getting started with DLinq, which allows you to write Linq queries against databases. Once you're up to speed, you can take a database and be writing Linq queries against it in under five minutes!

In future parts in this series of posts, we'll look at doing database updates, writing more complex queries and debugging. In this one, we'll just look at doing some simple queries.

Creating The Linq to SQL Classes

The bad news is that before you can use DLinq, you have to create Linq to SQL classes to represent your database tables. The good news is that Visual Studio 2008 (aside from the Express Edition) can do all of the hard work for you in this.

Read More
Tags: .NET, C#, DLinq

Subscribe

RSS Feed RSS Feed

More Tags

.NET C C# C# 3.0 C++ Embedded engineering service eveh3d firmware Hardware Linux Made-In-China offshore Operating System Outsource Perl product development Programming R&D Software

Help

Check out the Blog FAQ.




Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.