LINQ to SQL is a component of .NET Framework version 3.5 that provides a run-time infrastructure for managing relational data as objects.
400
votes
11answers
130k views
Entity Framework vs LINQ to SQL
Now that .NET v3.5 SP1 has been released (along with VS2008 SP1), we now have access to the .NET entity framework.
My question is this. When trying to decide between using the Entity Framework and ...
77
votes
12answers
32k views
Random row from Linq to Sql
What is the best (and fastest) way to retreive a random row using Linq to SQL when I have a condition, e.g. some field must be true ?
29
votes
3answers
12k views
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 ...
88
votes
16answers
13k views
Is LINQ to SQL Dead or Alive?
Just when I make friends with LINQ to SQL, it appears as though MS is pulling the rug out from under it.
...
219
votes
7answers
26k views
Returning IEnumerable<T> vs IQueryable<T>
what is the difference between returning iqueryable vs ienumerable.
IQueryable<Customer> custs = from c in db.Customers
where c.City == "<City>"
select c;
IEnumerable<Customer> ...
72
votes
10answers
43k views
LINQ to SQL: Return anonymous type?
Using the simple example below, what is the best way to return results from multiple tables using Linq to Sql?
Say I have two tables:
Dogs: Name, Age, BreedId
Breeds: BreedId, BreedName
I want ...
128
votes
24answers
56k views
LINQ-to-SQL vs stored procedures? [closed]
I took a look at the "Beginner's Guide to LINQ" post here on StackOverflow (http://stackoverflow.com/questions/8050/beginners-guide-to-linq), but had a follow-up question:
We're about to ramp up a ...
41
votes
3answers
12k views
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 ...
5
votes
4answers
355 views
Making Entity Class Closed for Changes
I have a database relationship as shown below. The domain objects are created based on LINQ to SQL ORM.
A payment comprises of Cash Payment and Gift Coupon Payments. Suppose the total amount of ...
68
votes
5answers
45k views
efficient way to implement paging
Should I use LINQ's Skip() and Take() method for paging, or implement my own paging with a SQL query?
Which is most efficient? Why would I choose one over the other?
I'm using SQL Server 2008, ...
85
votes
5answers
59k views
Linq to Sql: Multiple left outer joins
I'm having some trouble figuring out how to use more than one left outer join using LINQ to SQL. I understand how to use one left outer join. I'm using VB.NET. Below is my SQL syntax.
T-SQL
...
108
votes
4answers
100k views
LINQ - Left Join, Group By, and Count
Let's say I have this SQL:
SELECT p.ParentId, COUNT(c.ChildId)
FROM ParentTable p
LEFT OUTER JOIN ChildTable c ON p.ParentId = c.ChildParentId
GROUP BY p.ParentId
How can I translate this into ...
48
votes
4answers
41k views
LINQ to SQL Left Outer Join
Is this query equivalent to a LEFT OUTER join?
//assuming that I have a parameter named 'invoiceId' of type int
from c in SupportCases
let invoice = c.Invoices.FirstOrDefault(i=> i.Id == ...
63
votes
4answers
58k views
LINQ to SQL - Left Outer Join with multiple join conditions
I have the following SQL, which I am trying to translate to LINQ:
SELECT f.value
FROM period as p
LEFT OUTER JOIN facts AS f ON p.id = f.periodid AND f.otherid = 17
WHERE p.companyid = 100
I have ...
104
votes
10answers
51k views
LINQ: When to use SingleOrDefault vs. FirstOrDefault() with filtering criteria
Consider the IEnumerable extension methods SingleOrDefault() and FirstOrDefault()
MSDN documents that SingleOrDefault:
Returns the only element of a sequence, or a default value if the sequence ...