Questions tagged [linq-to-sql]

This tag is NOT ABOUT LINQ TO SQL TRANSLATION! Linq to SQL is an old ORM that's part of .Net framework, not core. For questions about LINQ to SQL translation please use the tag of the ORM in question.

LINQ to SQL

LINQ to SQL is a component of .NET Framework version 3.5 that provides a run-time infrastructure for managing relational data as objects stored in Microsoft SQL Server. The tag linq-to-entities should be used for questions about Entity Framework LINQ queries.

LINQ to SQL maps the data model of a relational database to an object model expressed in the programming language of the developer. When the application runs, LINQ to SQL translates the language-integrated queries in the object model into SQL and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language.

As of 2008, LINQ to SQL is no longer being actively developed, and Microsoft recommends using Entity Framework instead.

Introduction

Using LINQ to SQL

More information

14803 questions
5
votes
3 answers

Linq to Sql Group By Class

I would like to pass a groupedList to several functions, however I'm getting strange results when trying to group by using a class rather than an anonymous type. In the following example the anonymous type returns 2 results, as expected, but the…
SumGuy
  • 602
  • 7
  • 18
5
votes
1 answer

Tracking down a stack overflow error in my LINQ query

I've written the following LINQ query: IQueryable entries = (from e in competitorRepository.Competitors join c in countries on e.countryID equals c.isoCountryCode where !e.Deleted orderby c.isoCountryCode select new…
Lazarus
  • 41,906
  • 4
  • 43
  • 54
5
votes
3 answers

Does Linq to SQL or Linq to Entities 4.0 support the hierarchyid datatype

Is their a way to use linq to SQL/Entities 4.0 to work with the hierarchy datatype?
Luke101
  • 63,072
  • 85
  • 231
  • 359
5
votes
2 answers

Linq filtering an IQueryable (System.Data.Linq.DataQuery) object by a List (System.Collection.Generic.List) object?

My IQueryable line is: // find all timesheets for this period - from db so System.Data.Linq.DataQuery var timesheets = _timesheetRepository.FindByPeriod(dte1, dte2); My List line is: // get my team from AD - from active directory so…
Klaptrap
  • 311
  • 3
  • 19
5
votes
4 answers

The null value cannot be assigned to a member with type System.Int64 which is a non-nullable value type

I'm getting the following error in my MVC2 app using Linq to SQL (I am new to both). I am connected to an actual SQL server not weird mdf: System.InvalidOperationException The null value cannot be assigned to a member with type System.Int64 which is…
BritishDeveloper
  • 13,219
  • 9
  • 52
  • 62
5
votes
2 answers

Dynamic Linq help, different errors depending on object passed as parameter?

I have an entityDao that is inherbited by everyone of my objectDaos. I am using Dynamic Linq and trying to get some generic queries to work. I have the following code in my generic method in my EntityDao : public abstract class…
SventoryMang
  • 10,275
  • 15
  • 70
  • 113
5
votes
4 answers

[C#]How to introduce retry logic into LINQ to SQL to deal with timeouts?

I need to find ways to add retry mechanism to my DB calls in case of timeouts, LINQ to SQL is used to call some sprocs in my code... using (MyDataContext dc = new MyDataContext()) { int result = -1; //denote failure int count = 0; while…
Chris
  • 657
  • 1
  • 9
  • 17
5
votes
3 answers

LINQ-To-SQL and Many-To-Many Relationship Deletions

I have a many-to-many relationship between two tables, let's say Friends and Foods. If a friend likes a food I stick a row into the FriendsFoods table, like this: ID Friend Food 1 'Tom' 'Pizza' FriendsFoods has a Primary Key 'ID', and two non-null…
Jake
  • 7,565
  • 6
  • 55
  • 68
5
votes
1 answer

Can't Add LINQ to SQL classes to projects in VS2010

I just ran into something in Visual Studio 2010 RC that wasn't previously happening (like, yesterday). No software changes here, but I did run into some muck yesterday when compiling that required a reboot. I am unable to add LINQ to SQL classes to…
MisterJames
  • 3,306
  • 1
  • 30
  • 48
5
votes
1 answer

T-SQL selecting values that match ISNUMERIC and also are within a specified range. (plus Linq-to-sql)

I am trying to select rows from a table where one of the (NVARCHAR) columns is within a numeric range. SELECT ID, Value FROM Data WHERE ISNUMERIC(Value) = 1 AND CONVERT(FLOAT, Value) < 66.6 Unfortunately as part of the SQL spec the AND clauses…
Toby
  • 2,333
  • 3
  • 16
  • 10
5
votes
3 answers

How can I do a multi level parent-child sort using Linq?

How can I do a multi-level parent-child sort using Linq if I have a table structure like the one below: [Table: Sections] Id Seq Name ParentSectionId 1 1 TOP NULL 2 1 AAAA 1 3 2 SSSS 1 4…
Tenacious T
  • 65
  • 1
  • 6
5
votes
1 answer

Using ASP.NET MVC, Linq To SQL, and StructureMap causing DataContext to cache data

I'll start by telling my project setup: ASP.NET MVC 1.0 StructureMap 2.6.1 VB I've created a bootstrapper class shown here: Imports StructureMap Imports DCS.Data Imports DCS.Services Public Class BootStrapper Public Shared Sub…
Dragn1821
  • 807
  • 2
  • 8
  • 19
5
votes
1 answer

LINQ to SQL: InsertOnSubmit() vs Add()

What is the best way to insert new child records: to use Add() or InsertOnSubmit() ? Is there any difference between those to approaches ? InsertOnSubmit() example: using (DataContext db = new DataContext()) { Parent p = db.Parents.Where(q =>…
koryakinp
  • 3,989
  • 6
  • 26
  • 56
5
votes
2 answers

Linq to sql - delete some related records

I´m using linq to sql and I have a lot of tables with foreign keys leading to the UserId. Is it possible to have some of these foreign tables cleaned upon deletion. For example I want the users profile (other table) to be deleted automatically with…
Oskar Kjellin
  • 21,280
  • 10
  • 54
  • 93
5
votes
3 answers

Could model unit tests be truly independent and how [ASP.NET MVC]

I am new to the whole unit testing stuff, so please excuse my lack of experience. I've read a lot of materials saying that no test should depend on others to do, i.e unit tests be completely independent form each other. Can you really do that in…
xantrus
  • 1,975
  • 1
  • 22
  • 44