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

Is Typemock the only framework that can mock a Linq To SQL Table class?

I am trying to setup unit tests for my Linq To SQL code. My code uses the System.Data.Linq.Table class (generated by the designer). Because this class is sealed and the constructor is internal it is completely impervious to unit testing frameworks…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
5
votes
2 answers

Converting IQueryable results to comma delimited string
I have a LINQ query that returns all absences for an employee. The first part of the linq statement gets a basic list of the employees details, but I also return an IQueryable list of illnesses related to that absence. I'd like to somehow convert…
Fermin
  • 34,961
  • 21
  • 83
  • 129
5
votes
3 answers

Is it possible to use Linq-SQL without drag-and-drop?

If i want to use Linq-SQL i also have to drag the DB Table unto the designer surface to create the entity classes. I always like full control in my application and do not like the classes created by dotnet. Is it possible to provide this connection…
Orson
  • 14,981
  • 11
  • 56
  • 70
5
votes
2 answers

Conditional shortcuts in LinqToSql query

Here's a little LinqToSql GOTCHA: // Returns the number of counties in a state, // or all counties in the USA if the state is null public static int CountCounties(State s) { var q = from cy in County.GetTable() // my method to get the…
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
5
votes
2 answers

An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext

I've got a problem with NotSupportedException, I'm getting: "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext." partial class SupplyOfert : Model { public SupplyOfert(int id…
kryski
  • 414
  • 2
  • 6
  • 18
5
votes
3 answers

Linq to Sql case insensitive equality

I am reading contradictory explanations on Linq to Sql string comparisons. When I do the following: from p in db.People where p.UserName=username select p username="jOHn" I get the correct case insensitive result. Is Linq doing this by…
zsharp
  • 13,656
  • 29
  • 86
  • 152
5
votes
2 answers

Linq query with multiple count

I am trying to query this table using LINQ: Here's what I want to do: Here's my LINQ query: var query = from a in table where a.Country.Equals("USA") group a by a.Product_brand into grp select new …
Zack09
  • 103
  • 2
  • 8
5
votes
1 answer

How to convert type 'byte[]' to 'System.Data.Linq.Binary'

I have a WorkflowInstances table in my DB which contains this fields: ID (int), Name (nvarchar(50), WorkflowID (int), Document (varbinary(MAX))). I want to insert a new WorkflowInstance so I wrote this code Stream myStream =…
Anas Salem
  • 177
  • 1
  • 2
  • 13
5
votes
2 answers

linq search multiple columns

I want to search for a string in multiple columns using ling-to-sql and I'm wondering how to write the where clause. This is what I have: I'm passing a list of IDs to search as well as a search term: public List Seach(string TheSearchTerm,…
frenchie
  • 51,731
  • 109
  • 304
  • 510
5
votes
2 answers

OrderByDescending() per MSDN, what on earth does this mean?

Can someone please help be take apart the elements here and help me understand what they are? public static IOrderedEnumerable OrderByDescending( this IEnumerable source, Func
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
5
votes
3 answers

Why doesn't OR designer let me drag tables to design surface?

I have a database hosted at somee.com I have added a new connection in Server Explorer in VS 2012 and the test connection was successful. I can also successfully see the tables in the SE and any changes made to the database from the admin panel @…
user1705923
5
votes
1 answer

linq remove items from query where any list value is present

I am trying to retrieve this in linq but can't seem to figure it out. I want to filter a query based on if a value in the query exist in a list but remove those items from the query. Let say I have a list of ids List UserIds = new List();…
Jake
  • 1,332
  • 5
  • 23
  • 35
5
votes
3 answers

What is the Maximum Number of Records i can insert through InserAllOnSubmit() In Linq to Sql

I'm reading the Excel sheet and applying My business logic and i'm trying to insert using Linq to SQL. In my loop i have > (greater than) 5,000 records and < (Less than) 15,000 records to Insert. public List tblLogList = new List();…
RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
5
votes
4 answers

Differences between LINQ to Objects and LINQ to SQL queries

I have been using LINQ to query my POCO objects for some time, but I have not yet tried LINQ to SQL. I assume that LINQ to SQL queries are somehow converted to equivalent SQL queries and, given this, I am wondering if that affects the way LINQ to…
GraemeF
  • 11,327
  • 5
  • 52
  • 76
5
votes
3 answers

UNITY: passing in a new datacontext each time?

I am trying to use unity to automatically inject a datacontext on my repository using a new instance each time.., my idea is the ensure that each time a new datacontext is injected Currently its failing on creating the repository, i think it can't…