linq-to-sql

Benchmark Linq2SQL, Subsonic2, Subsonic3 - Any other ideas to make them faster ?

I am working with Subsonic 2 more than 3 years now... After Linq appears and then Subsonic 3, I start thinking about moving to the new Linq futures that are connected to sql. I must say that I start move and port my subsonic 2 with SubSonic 3, and very soon I discover that the speed was so slow thats I didn't believe it - and starts al...

Performing a INSERT INTO ... SELECT with LINQ to SQL

I'm trying to figure out if it's possible to perform an "insert into ... select" type command with LINQ to SQL. A bit of LINQ to SQL code that would allow me to send one single SQL command to the database that would insert multiple rows into a given table. For example, how to make LINQ to SQL send the following T-SQL statement to an SQ...

VS2010 Using SQL Server 2000

Is there a way to use the SQL Model (dbml) builder in VS2010 using SQLServer2000? It works fine in VSExpress2008 + VS2008 but throws an "Upgrade SQL to 2005" error in VS2010 which seems a tad unreasonable. ...

Linq To SQL: Distinct with First or Default

I have a table of Departments that is related to an Employees table. What I want is a list that contains one Employee for every Department. It doesn't matter which employee, so TOP 1, is fine. But each Department should only be represented by one employee in the list. EMPLOYEES >----------DEPARTMENT Id Id LastName ...

Returning partial address matches and mismatch position using L2S or SQL

I need to implement a method that takes an address split up into individual parts and returns any matching items from an address table. If no matches are found, I want to be able to return a value indicating where it failed. Each input param has a corresponding field in the table. The signature would look something like this: List<Add...

Linq to Sql Sum with no records

I am creating a method that collects accumulated totals throughout the month. The problem is that there may not be charges for some of the items in a given month so no rows would be returned. I can see how this would error with no data: double fuelCost = (double)(from a in db.EquipmentFuelLogs where a.wdEqui...

Programmatically change how a property in a Select is populated in an LINQ to SQL query

I'm writing a bit of LINQ to SQL that needs to perform a search for client information in our database, filtering the results and paging them. The filtering needs to be dynamic so I have broken the setup of the query into four stages: Find visible clients (basically apply a coarse grained filter) Filter clients by search criteria Sort ...

C# - Linq to SQL , type conversion error

Hi folks, new to LINQ & would like to know why the error & best way to resolve. I am getting, 'Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?)' error List<string> names = new List<string>(); names.Add("audi a2"); names....

How do I do this lamba statement as Linq To Sql?

Hi folks, how can the ThenBy be translated to Linq-To-Sql, please? var movies = _db.Movies.Orderby(c => c.Category).ThenBy(n => n.Name) var movies = from m in _db.Movies orderby m.Category // What's the syntax for ThenBy?! // thenby m.Name select m; When i try to do thenby m.Name...

Delete from multiple tables (linq to sql)

hi, I'm using Linq to SQL to access my database. I want to have a 'delete account' feature which basically gets rid of all records in all tables that belong to a given user. What would be the most efficient way of doing this? The deletion has to occur in a certain order, otherwise there are foreign key integrity errors. I can do this m...

ASP.NET MVC and LINQ to SQL: linking table, checkboxes

I am very new to MVC and from what I learned, I can have a form (a View) linked to a Model. Now I have a View for adding a new Client, so the View inherits from Client. I have something like this for each field <%= Html.LabelFor(model => model.FirstName) %> <%= Html.TextBoxFor(model => model.FirstName)%> <%= Html.ValidationMessag...

How to create SQL Database from Linq2Sql Model

Is it possible to create a SQL DB from a Linq2Sql model? I managed to lose a DB for something I started building a year ago, but have the Linq2Sql model. If this is possible, what are the steps? ...

Using contains() in LINQ to SQL

I'm trying to implement a very basic keyword search in an application using linq-to-sql. My search terms are in an array of strings, each array item being one word, and I would like to find the rows that contain the search terms. I don't mind if they contain more than just the search terms (most likely, they will), but they all the sea...

select n random rows via linq2sql

i know of using the ORDER BY NEWID() feature when running a regular sql command. I'm wanting to do the same thing, but via linq2sql. I'd prefer not to select the whole range, add in a random number via rnd.Next(), and then sort by that... ...

Help with LINQ query

I'm trying to retrieve columns based on their corresponding key. "Select * from diamond where p_Id="+p_Id I followed MSDN sample and they were doing it like this way: CurrencyManager cm = ((CurrencyManager)this.BindingContext[myDatabaseDataSet, "Items.ItemDiamond"]); IBindingList list = (IBindingList)cm.List; but lis...

What is LINQ to SQL template? What is the advantage of it?

What is LINQ to SQL template? What is the advantages of it? ...

InsertOnSubmit doesn't attach?

After creating a new object (Foo), I set the key (BarId) for an EntityRef association property (Bar). I then want to insert the new object into the database, and be able to access the lazy-loaded child object afterward. Unfortunately, the lazy-loading property returns null after the call to InsertOnSubmit(). It returns the correct obj...

How Do LINQ TO SQL Stored Procedure Calls Work?

I have a LINQ TO SQL Context that I have created that calls a stored proc. When I'm looping through the ISingleResult is it creating entities on the fly while the underlying DataReader reads the results or does it put every thing into Entities upfront before the function call returns. Basically what is going on is I'm working with a sto...

Help with the following linq query?

Take the following linq query: var summary = results.Select(r => new { TotalPopulation = results.Sum(s => s.Population), TotalGross = results.Sum(s => s.Gross), }).Distinct(); The above work...

Is it possible to search a dbml diagram?

This is not an issue with a few tables, but when I have a ton of tables on my dbml diagram, I have to pan and zoom to find the table I am looking for. Is there a way to search the dbml diagram so it automatically goes to the table I searched for? ...