211
votes
46answers
17k views

What are the pros and cons to keeping SQL in Stored Procs versus Code

What are the advantages/disadvantages of keeping SQL in your C# source code or in Stored Procs? I've been discussing this with a friend on an open source project that we're working on (C# ASP.NET ...
141
votes
22answers
6k views

Joins are for lazy people?

I recently had a discussion with another developer who claimed to me that JOINs (SQL) are useless. This is technically true but he added that using joins is less efficient than making several requests ...
119
votes
9answers
119k views

What is the syntax for an inner join in linq to sql?

I'm writing a linq to sql statement & I'm just after the standard syntax for a normal inner join with an 'on' clause in C#. ie how do you represent this in LINQ to SQL?: select * from table1 ...
101
votes
10answers
76k views

What represents a double in sql server?

I have a couple of properties in C# which are double and I want to store these in a table in SQL Server, but noticed there is no double type, so what is best to use, decimal or float? This will store ...
83
votes
8answers
42k views

Validation failed for one or more entities while saving changes to SQL Server Database

I want to save my Edit to Database and I am using Entity FrameWork Code-First in ASP.NET MVC 3 / C# but I am getting errors. In my Event class, I have DateTime and TimeSpan datatypes but in my ...
82
votes
10answers
34k views

Fastest Way of Inserting in Entity Framework

i'm looking for the fastest way of INSERTING in Entity Framework, i'm asking this because of the scenario where you have an active TransactionScope and the insertion is Huge (4000+), it can ...
62
votes
4answers
54k 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 ...
53
votes
5answers
28k views

How to use DbContext.Database.SqlQuery<TElement>(sql, params) with stored procedure? EF Code First CTP5

I have a stored procedure that has three parameters and I've been trying to use the following to return the results: context.Database.SqlQuery<myEntityType>("mySpName", param1, param2, param3); ...
35
votes
9answers
26k views

Parsing SQL code in C# [duplicate]

I want to parse SQL code using C#. Specifically, is there any freely available parser which can parse SQL code and generate a tree or any other structure out of it? It should also generate the proper ...
33
votes
10answers
24k views

What's the fastest way to bulk insert a lot of data in SQL Server (C# client)

I am hitting some performance bottlenecks with my C# client inserting bulk data into a SQL Server 2005 database and I'm looking for ways in which to speed up the process. I am already using the ...
31
votes
3answers
5k views

What is the difference between “LINQ to Entities”, “LINQ to SQL” and “LINQ to Dataset”

I've been working for quite a while now with LINQ. However, it remains a bit of a mystery what the real differences are between the mentioned flavours of LINQ. The successful answer will contain a ...
31
votes
8answers
20k views

Passing List<> to SQL Stored Procedure

I've often had to load multiple items to a particular record in the database. For example: a web page displays items to include for a single report, all of which are records in the database (Report is ...
29
votes
6answers
9k views

When should I open and close a connection to SQL Server

I have a simple static class with a few methods in it. Each of those methods open a SqlConnection, query the database and close the connection. This way, I am sure that I always close the connection ...
28
votes
7answers
24k views

How to get last inserted id?

I have this code: string insertSql = "INSERT INTO aspnet_GameProfiles(UserId,GameId) VALUES(@UserId, @GameId)"; using (SqlConnection myConnection = new SqlConnection(myConnectionString)) { ...
28
votes
4answers
17k views

Use linq to generate direct update without select

G'day everyone. I'm still learning LINQ so forgive me if this is naive. When you're dealing with SQL directly, you can generate update commands with conditionals, without running a select statement. ...

1 2 3 4 5 611
15 30 50 per page