All Questions

Tagged with
Filter by
Sorted by
Tagged with
766votes
33answers
504kviews

Fastest Way of Inserting in Entity Framework

I'm looking for the fastest way of inserting into Entity Framework. I'm asking this because of the scenario where you have an active TransactionScope and the insertion is huge (4000+). It can ...
user avatar
  • 9,070
467votes
19answers
648kviews

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 ...
user avatar
  • 32.6k
366votes
8answers
424kviews

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 ...
user avatar
  • 44.1k
340votes
17answers
320kviews

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 ...
user avatar
  • 3,973
330votes
24answers
311kviews

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(...
user avatar
  • 3,679
274votes
47answers
76kviews

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 ...
270votes
30answers
268kviews

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 { ...
user avatar
  • 8,877
268votes
10answers
345kviews

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); ...
user avatar
183votes
16answers
231kviews

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)) { ...
user avatar
  • 11.7k
182votes
24answers
247kviews

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 ...
user avatar
169votes
21answers
8kviews

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 ...
user avatar
161votes
10answers
188kviews

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: ...
user avatar
  • 1,767
153votes
7answers
156kviews

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 ...
user avatar
  • 5,506
151votes
10answers
313kviews

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, ...
user avatar
  • 3,482
133votes
7answers
318kviews

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 { ...
user avatar
  • 4,763

15 30 50 per page
1
2 3 4 5
2145