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
67
votes
6 answers

LINQ to SQL using GROUP BY and COUNT(DISTINCT)

I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query from a in tpoll_answer where a.poll_nbr = 16 select a.answer_nbr, a.user_nbr…
Leandro López
  • 2,185
  • 1
  • 15
  • 17
66
votes
6 answers

Am I misunderstanding LINQ to SQL .AsEnumerable()?

Consider this code: var query = db.Table .Where(t => SomeCondition(t)) .AsEnumerable(); int recordCount = query.Count(); int totalSomeNumber = query.Sum(); decimal average = query.Average(); Assume query takes a very…
Ocelot20
  • 10,510
  • 11
  • 55
  • 96
65
votes
4 answers

How to write Asynchronous LINQ query?

After I read a bunch of LINQ related stuff, I suddenly realized that no articles introduce how to write asynchronous LINQ query. Suppose we use LINQ to SQL, below statement is clear. However, if the SQL database responds slowly, then the thread…
Morgan Cheng
  • 73,950
  • 66
  • 171
  • 230
62
votes
8 answers

Linq to SQL DateTime values are local (Kind=Unspecified) - How do I make it UTC?

Isn't there a (simple) way to tell Linq To SQL classes that a particular DateTime property should be considered as UTC (i.e. having the Kind property of the DateTime type to be Utc by default), or is there a 'clean' workaround? The time zone on my…
ericsson007
  • 643
  • 1
  • 5
  • 6
59
votes
5 answers

What is difference between .edmx and .dbml file in linq?

What is difference between .edmx and .dbml file in linq?In VS 2008 which datasource is best choice where edmx or dbml?Any problem will arise using edmx file in VS 2008?Can i use edmx in VS-2008?
user649802
  • 3,243
  • 3
  • 20
  • 14
59
votes
1 answer

How do I convert multiple inner joins in SQL to LINQ?

I've got the basics of LINQ-to-SQL down, but I've been struggling trying to get JOINs to work properly. I'd like to know how to convert the following to LINQ-to-SQL (ideally using method chaining, as that is my preferred format). SELECT …
Ed Sinek
  • 4,829
  • 10
  • 53
  • 81
59
votes
5 answers

What is the difference between Entity Framework and LINQ to SQL by .NET 4.0?

I was checking 2nd edition of Professional ASP.NET MVC and realized EF replaced LINQ to SQL. I am familiar to LINQ to SQL from the first book but I know nothing about EF. Anyway while reading the code, it seems like nothing has changed except the…
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
59
votes
9 answers

LINQ with SQLite (linqtosql)

I have a small project that require a storage (I choose SQLite) and I got good result with the ADO DLL for .Net for Sqlite. After the Install, I noticed that it contain a SQLLinq.dll. Before investigating too much effort, and because I haven't see…
Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
58
votes
7 answers

How are people unit testing code that uses Linq to SQL

How are people unit testing code that uses Linq to SQL?
Peter
  • 3,563
  • 5
  • 30
  • 43
58
votes
3 answers

Will using LINQ to SQL help prevent SQL injection

I'm setting up a public site and the first thing on my mind is SQL injection. I have some text fields I'm saving and am using linq to update/write to the database. Am I safe using linq? This example is creating the user account.…
Bill Martin
  • 4,825
  • 9
  • 52
  • 86
58
votes
7 answers

Is LINQ to SQL deprecated?

Back in late 2008 there was a lot of debate about the future of LINQ to SQL. Many suggested that Microsoft's investments in the Entity Framework in .NET 4.0 were a sign that LINQ to SQL had no future. I figured I'd wait before making my own…
Mayo
  • 10,544
  • 6
  • 45
  • 90
58
votes
8 answers

Nullable object must have a value?

On the line: bool travel = fill.travel.Value; I am getting the following error: Nullable object must have a value and i am not sure why. All I want to do is get the value in the database of travel which is currently false. Any help would be…
Sealer_05
  • 5,346
  • 8
  • 35
  • 53
57
votes
3 answers

When should I dispose of a data context

I'm currently writing a data access layer for an application. The access layer makes extensive use of linq classes to return data. Currently in order to reflect data back to the database I've added a private data context member and a public save…
Mykroft
  • 13,077
  • 13
  • 44
  • 72
57
votes
13 answers

System.Data.SqlClient.SqlException: Invalid object name 'dbo.Projects'

My MVC app is returning SqlExceptions when trying to access any table in my database. Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Projects'. My app us linq for the data layer. If I use an old dll it works fine,…
Trev
56
votes
5 answers

Nested stored procedures containing TRY CATCH ROLLBACK pattern?

I'm interested in the side effects and potential problems of the following pattern: CREATE PROCEDURE [Name] AS BEGIN BEGIN TRANSACTION BEGIN TRY [...Perform work, call nested procedures...] END TRY BEGIN CATCH …
David
  • 24,700
  • 8
  • 63
  • 83