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

Is there an advantage to USING vs. declaring a context variable?

These two snippets do the same thing - is there one that's better than the other, or is it just a matter of preference? Using context As MyDatabaseDataContext = New MyDatabaseDataContext() Dim test = context.Employees.Count End Using vs. Dim…
gfrizzle
  • 12,419
  • 19
  • 78
  • 104
5
votes
1 answer

Get average of the difference in datetime columns?

I have an Item class public class Item { //... public DateTime CreateDate { get; set; } public DateTime EndDate { get; set; } } In a method, I have List items. How would I query average of date differences in days more succinctly…
Josh
  • 1,019
  • 3
  • 17
  • 32
5
votes
2 answers

Entity Framework - Select specific columns and return strongly typed without losing cast

I'm trying to do something similar to this post where I don't pull back all columns from a particular entity, however my framework makes use of inheritence and I lose scope of the entity type after it's been cast to an anonymous type. The structure…
XVargas
  • 1,512
  • 2
  • 13
  • 16
5
votes
5 answers

LINQ to SQL Peculiarities

I'm encountering some peculiarities with LINQ to SQL. With a relatively simple query, I want to select some fields, but have the date fields formatted as strings, which I first achieved like this: var list = dataContext.MyLists.Single(x =>…
littlecharva
  • 4,224
  • 8
  • 45
  • 52
5
votes
1 answer

Get child record using Linq

This is my first time to hear about LINQ and I have no idea about it. Please be gentle on me. I have this set of data. +---------+--------+---------------+ | RadioID | NodeID | SourceRadioID | +---------+--------+---------------+ | R0 | 1…
Skinny Pipes
  • 1,025
  • 6
  • 14
5
votes
5 answers

Get Birthday reminder Linq Query ignoring year

Am using C# MVC and i need to get the user details who having birthday with in next 20 days. using linq to sql query which wants to compare only date and month and not the year, to fetch the users who having birthday within next 20days, anyone…
kart
  • 625
  • 3
  • 12
  • 21
5
votes
2 answers

Refactoring Func into Expression>

I have a method that currently takes a Func as a parameter, but I need it to be an Expression>. Using AdventureWorks, here's an example of what I'd like to do using the Func. private static void…
Ecyrb
  • 2,060
  • 3
  • 26
  • 44
5
votes
3 answers

Using Linq with WCF

I am looking for any examples or guides to using Linq over WCF (n-tier application). Please specify if you are showing something for Linq-to-SQL or Linq-to-entities. I would like to see usage examples for both. I am wondering how things like…
Phobis
  • 7,524
  • 10
  • 47
  • 76
5
votes
2 answers

Can Entity Framework deal with multiple result sets (each from joined tables) from a stored procedure?

In Linq to SQL, I can't find an easy way to deal with multiple result sets returned by a stored procedure where each result set is from table joins. Each result set does not map directly to a table. (can't change this behavior). For now, it seems…
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
5
votes
4 answers

Linq to Sql - Populate JOIN result into a List

I am not sure if this can be done, but here's the scenario. I want to turn this sql into linq: SELECT * FROM Department d INNER JOIN Employee e ON e.DepartmentID = d.DepartmentID Department - Employee is 1 to many relationship. I have created a…
David
  • 5,356
  • 2
  • 26
  • 39
5
votes
2 answers

Query Linq Join Many to Many

I'm using Linq-SQL Entity for my MVC2 Application. I have those tables / entities Person ( ID , Name , Surname ) Car (ID , Model , Name) Reseller ( ID , Name) And i have those 2 Many to Many Tables Persons_Cars ( ID , ID_Person , ID_CAR)…
Teresa
  • 65
  • 1
  • 1
  • 4
5
votes
3 answers

ASP.NET search form - dynamic Linq to SQL?

I have a search form that allows users to search on several different fields in several different ways. Here is an example of my code. var claims = from c in db.Claims select c; switch (ddlSearchField.Text) { case "StartsWith": claims =…
tom d
  • 1,023
  • 1
  • 8
  • 10
5
votes
2 answers

Updating disconnected entity that has child entities in linq to sql

In an n-tier application linq-to-sql doesn't seem to have a clear cut solution for updating a disconnected entity that has child EntitySets. I have some linq-to-sql entities... public partial class Location : INotifyPropertyChanging,…
bflemi3
  • 6,698
  • 20
  • 88
  • 155
5
votes
6 answers

Is it a bad idea to jump into LINQ to SQL now?

I have been using ADO.NET in favor of LINQ to SQL (or Entities) up to this point. I'm starting a new project that should be smallish, at least at first but I would like to have room to expand down the line. I feel now is a good time to get into…
Mike
  • 2,912
  • 4
  • 31
  • 52
5
votes
1 answer

how to design Repository pattern to be easy switch to another ORM later?

I am new to repository pattern but i tried, my goal is to make a design which will let me easily with just some few edits "dependency injection, or configuration edits" to be able to switch to another ORM without touching other solution layers. I…
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
1 2 3
99
100