All Questions
33,067
questions
811
votes
32
answers
587k
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 ...
484
votes
18
answers
691k
views
What is the syntax for an inner join in LINQ to SQL?
I'm writing a LINQ to SQL statement, and I'm after the standard syntax for a normal inner join with an ON clause in C#.
How do you represent the following in LINQ to SQL:
select DealerContact.*
from ...
389
votes
9
answers
501k
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 ...
372
votes
25
answers
395k
views
Entity Framework. Delete all rows in table
How can I quickly remove all rows in the table using Entity Framework?
I am currently using:
var rows = from o in dataDb.Table
select o;
foreach (var row in rows)
{
dataDb.Table.Remove(...
339
votes
17
answers
325k
views
Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework
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 ...
303
votes
32
answers
334k
views
Generate class from database table
How can I generate a class from a SQL Server table object?
I'm not talking about using some ORM. I just need to create the entities (simple class). Something like:
public class Person
{
...
278
votes
10
answers
384k
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);
...
274
votes
47
answers
80k
views
What are the pros and cons to keeping SQL in Stored Procs versus Code [closed]
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 ...
195
votes
28
answers
288k
views
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
I make an outer join and executed successfully in the informix database but I get the following exception in my code:
DataTable dt = TeachingLoadDAL.GetCoursesWithEvalState(i, bat);
Failed to ...
190
votes
18
answers
248k
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))
{
...
170
votes
10
answers
227k
views
Distinct in Linq based on only one field of the table
I am trying to use .distinct in Linq to get result based on one field of the table (so do not require a whole duplicated records from table).
I know writing basic query using distinct as followed:
...
169
votes
21
answers
8k
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 ...
168
votes
12
answers
359k
views
How to execute an .SQL script file using c#
I'm sure this question has been answered already, however I was unable to find an answer using the search tool.
Using c# I'd like to run a .sql file. The sql file contains multiple sql statements, ...
159
votes
7
answers
168k
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 ...
155
votes
8
answers
369k
views
Execute Insert command and return inserted Id in Sql
I am inserting some values into a SQL table using C# in MVC 4. Actually, I want to insert values and return the 'ID' of last inserted record. I use the following code.
public class MemberBasicData
{
...