linq-to-sql

LINQ to SQL, ExecuteQuery, etc

This might all be a bit subjective: Our organization has made a strong attempt to adopt LINQ to SQL as our primary data access method and for the most part this works well. (Let’s leave the EF out of the discussion.) Some of our developers find LINQ difficult and migrate back to traditional raw SQL via ExecuteQuery. We also utilize Ope...

How do I get to the bottom of this Linq to SQL error?

An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported. Having worked with Linq to SQL for some time, I believe that I know about its limitations and that I follow the rules when I write new code. But it is frustrating to get this excepti...

How Do I Avoid This Behavior?

Say I have an entity that looks as follows public Order OrderEntity { EntityRef<Customer> CustomerEntity; EntitySet<OrderDetail> OrderDetailEntity; ... ... } When I save a OrderEntity, L2S, will want to also save the entity in CustomerEntity and all the entities in OrderDetailEntity. Sometimes we want this beh...

Linq To Sql - Dynamic

I have two Tables: Table 1: Client Fields: Id_Client Char 5 Name_Client Char 50 Table 2: Country Fields: Id_Country Char 4 Name_Country Char 80 Population Int 15 With Sql I can make this 2 queries Select Id_Client, Name_Client from Client Select Id_Country, Name_Country, Population from Country I...

Linq To Sql 'Where Or' operator

I need to create a query which checks if a field (string) contains one or more words supplied at run time. Basically I need to be able to ask a WhereOr question. This seems like it should be a common issue when dealing with LinqToSql. I found the following reference but can't make sense out of it - and have no idea how to use it in my...

Why is Linq To Sql databinding to gridview much slower than pass-through SQL?

Hello, I have compared two queries which fetch some fairly large data from a database table. For query one I used Linq To Sql and for the other I use passthrough SQL via ADO.NET. I know that Linq To Sql has to do a lot of work behind the scenes, but what is it actually doing? The two queries fetches the same amount of data but the Linq...

Dynamic variables in linq select statement

I have a listbox that is dynamically filled by certain values depending on what table has been selected from another list box. Once a value is selected, it is being graphed vs a date & time range. With my ignorance of linq: depending on what value is selected, the linq to sql statement I need to create to grab data from my database is di...

Linq2Sql remove char

public ActionResult Index(string title) { var post = (from p in dataContext.Posts where RemoveChar(p.Title) == title && !p.Deleted select p).Single(); post.Visit = post.Visit + 1; dataContext.SubmitChanges(); return View(new ViewData.PostIndexViewData(p...

Multiple Inheritance in LINQtoSQL?

Guys, I have been surfing thru the web to find a way that I could use Multiple-Table-Inheritance in LINQ-To-SQL. But it looks like that it only supports single table inheritance which is not the best way to achieve inheritance in a ORM framework. I got to read that this will be addressed in next LINQ and Entity framework implementations....

How do I avoid immediate loading of associated data in Linq to SQL

Say I have an entity that looks as follows public Order OrderEntity { EntityRef<Customer> CustomerEntity; EntitySet<OrderDetail> OrderDetailEntity; ... ... } When I retrieve an OrderEntity, and convert it say to a List, L2S, will also retrieve the entity in CustomerEntity and all the entities in Or...

Linq To Sql - Changing Sort Order At Run-Time with well known static typing

This is not another question about 'How Can I Sort Dynamically (based on an arbitrary user provided field)?' The question is -- how can I change sort order when I know the potential sorts in advance? (And thus avoid reflection / custom Expression building typically associated with truly dynamic sorting.) Take for instance this subquery...

Multi Join Linq Statement

Is this the proper way to accomplish joining 3 (or more) tables with LINQ (to SQL)? Especially the select portion. Am I on the right track to return a single record(row) of data that spans across the tables? public static DataTable GetCurrentEmploymentQuestionnaire(Guid employmentQuestionnaireID) { var Questionnair...

Help with Linq to SQL; return one result from one to many relationship

I am trying to return a list of results, where the joined table has multiple values, but I only want one image value for each listing value. The SQL is like this: SELECT Title, Comments, ThumbNailPath, thumbheight, thumbwidth FROM Listings as l INNER JOIN Images as i ON l.id = i.ListingId WHERE (i.ImageSlot = 1) ...

Linq To Sql - Refactoring Complex Queries Into Smaller Parts throws NullReferenceException

I have a non-trivial Linq To Sql query that I'm trying to break down into pieces for the sake of readability / further filtering / reuse. The refactored code looks like this, where ids is the subquery performed to grab the ids. var results = from solution in context.csExtendedQAIncident_Docs join solutionText in contex...

LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with some of their more advanced queries and fall back on ExecuteQuery() to kind of do the LINQ thing. Queries that used to be easy in TSQL but ...

Linq to SQL: Ammend command before submission to database

Is there a hook somewhere within Linq to SQL that would allow me to manually modify a command before it is sent to the database? Specifically, I am trying to introduce the WITH CHANGE_TRACKING_CONTEXT(@contextData) syntax whenever an insert/update/delete is applied to the database in order to be able to add additional information agains...

SQL Server Search, how to return the total count of rows?

Hello, I have another post which resulted in this SELECT DISTINCT a.ArticleID, COUNT(*) AS KeywordMatch, a.Headline, a.ShortDescription, a.CategoryID, a.ArticleSectionImage, a.DatePublished FROM Article a JOIN SearchWords sw ON a.ArticleID = sw.ArticleID WHERE EXISTS ( ...

Asp.net MVC overiding default getter and setters for linq to sql, for doing UTC conversions

Hi All, I'm getting to a point with my app where I'm about to try to roll out utc support. I've already got it all working and have written myself two utility classes, called convertToUtc and convertFromUtc. I think you can guess what they do. What I was thinking though, could I build these into the getter and setter methods for my da...

Entity Framework Many-To-Many with additional field on Joining Table

I have an entity context that includes three tables (see diagram here). The first is a table that contain products, the second contains recipes. The joining table has fields for IDs in both the products and recipes table as well as a 'bit' field called 'featured'. I've searched and found no example on how to insert only how to select a...

Is it easier to go from LinqToSQL to EF4.0 or EF3.5 to EF4.0?

Now that Entity Framework 4.0 is coming out I was wondering, if you were planning to use EF 4.0 when it is released would it be easier to go from LinqToSQL to EF 4.0 or EF 3.5 to 4.0? In other words if you were starting a project now anticipating using EF4.0 would you use LinqToSQL or EF3.5 now? ...