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
2 answers

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...
benpage
  • 4,418
  • 3
  • 41
  • 39
5
votes
3 answers

Return empty string using Linq to SQL - Related table with no rows - ASP.Net MVC

I have 1 to many relationship with the following tables - Person and Email. When using linq to sql and ASP.Net MVC, I'd like to show the first email or an empty string in my Person view using code like this: <%=…
jlnorsworthy
  • 3,914
  • 28
  • 34
5
votes
3 answers

Reaching child records in a SQL Server table

Out of my lack of SQL Server experience and taking into account that this task is a usual one for Line of Business applications, I'd like to ask, maybe there is a standard, common way of doing the following database operation: Assume we have two…
rem
  • 16,745
  • 37
  • 112
  • 180
5
votes
1 answer

ASP.NET MVC AJAX post to controller action not working

In my ASP.NET MVC 4 view, the following is not calling controller action. Click event does get trigger because I can see the alert message. But when I put a breakpoint on the controller action in debug mode, the app does't get to that point and…
nam
  • 21,967
  • 37
  • 158
  • 332
5
votes
1 answer

Linq to SQL datacontext not updating for foreign key relationships

I'm writing a database test against a repository that uses L2S. In my database I have a Manifest entity and an AllocatedTransaction entity. The AllocatedTransaction entity has a foreign key to the Manifest's id. The DDL looks something like…
JChristian
  • 4,042
  • 5
  • 29
  • 34
5
votes
4 answers

Is there any way to delay- execute a delegate against an IQueryable after/during execution?

I expose an IQueryable method from my business layer for use in other layers. I would like to execute a function against each of the items in the enumeration, once the query has executed down-level. It seems like there should be an event that is…
Jason Wicker
  • 3,416
  • 2
  • 25
  • 32
5
votes
1 answer

Writing Lambda Query Expressions in VB.Net using linq to sql provider

I'm just not understanding on how to create a lambda expression instead of using a regular comprehension linq queries. All of the examples i see are not query a database using linq to sql. i want to able to construct a lambda expression that get my…
Michael
  • 53
  • 1
  • 3
5
votes
1 answer

Is there anyway to serilize linq object for Memcached?

I'm just start switching to memcached and currently on testing with memcached. I'm having 2 object, I created an object and put [Serializable] on it (for instance, let call this Object1), the other object is created using Linq DBML (Object2).. I…
DucDigital
  • 4,580
  • 9
  • 49
  • 97
5
votes
1 answer

The member has no supported translation to SQL. When trying to access a property in my Partial class in the LINQ to SQL statement. Lambda expression?

I have 3 tables in my database Country City House Country table looks like CountryID Name City table looks like CountryID CityID Name House CountryID CityID HouseID Name I use LINQ to SQL and the above tables become classes and…
soldieraman
  • 2,630
  • 7
  • 39
  • 52
5
votes
6 answers

How does this LINQ Expression work?

I know what this code is doing but I'm not sure on the syntax. It doesn't seem to conform to a "standard" format. Is it mostly LINQ? return db.Subjects.SingleOrDefault(s => s.ID == ID); The first part makes sense but it's the part in the brackets I…
user172632
5
votes
3 answers

Help with Error " 'object' does not contain a definition for 'Text' "

Here's the problem: This is for a WPF app that uses C# and LINQ to SQL. When a user wants to look at a list of customers, he/she begins entering the name in a textbox. The textchanged event uses the input text to define the where clause of a LINQ…
Jack McG
  • 595
  • 2
  • 6
  • 5
5
votes
2 answers

Linq-to-SQL - Calling stored procedure throwing exception in C#

I have a stored procedure that I'm calling in C# via Linq-to-SQL. I've got some code inside of my stored procedure to check the @@error value and if it's a non-zero value, I want to return a custom error message. I am trying to intentionally…
5
votes
1 answer

Azure table storage - where clause on column that may not exist

I am adding a new column to my azure table. For ex., the table is called 'User' and the new column is called 'ComputationDate'. The 'User' table already exists with rows that do not have this new column 'ComputationDate'. I have a query over it as…
user1198407
  • 381
  • 3
  • 16
5
votes
5 answers

How to get the primary key from a table without making a second trip?

How would I get the primary key ID number from a Table without making a second trip to the database in LINQ To SQL? Right now, I submit the data to a table, and make another trip to figure out what id was assigned to the new field (in an auto…
Erx_VB.NExT.Coder
  • 4,838
  • 10
  • 56
  • 92
5
votes
2 answers

How do I update a table with LINQ-to-SQL without having to delete all the existing records?

Lets say I have a simple table that only contains two columns: MailingListUser - PK ID (int) - FK UserID (int) I have a method called UpdateMailList(IEnumerable userIDs). How do I, in LINQ, make inserts for the userIDs that are present…
Bombafet
  • 53
  • 4