Tag: entity-framework

How to call a SQL Server procedure using Entity Framework 6

I have the following code in SQL Server: ALTER PROCEDURE Checking @name NVARCHAR(200), @password NVARCHAR(200) AS Begin SET NOCOUNT ON DECLARE @res int SELECT @res = COUNT(*) FROM [User] WHERE [User].Username = @name AND [User].PasswordHashed = HASHBYTES(‘SHA2_512’, @password) return @res END As you can see, the procedure is returning an Int32 value. In my C# […]

How do I resolve Exception from MVC App where datamodel contains 2 FK relationships to same table, using EF6?

I am developing an Web application using C#/MVC and EF6. I am using the Database First approach, as I am attaching to an existing database (SQL Server 2008-R2). I have one table that contains 2 foreign keys to the same target as follows: Table Artifact: int ArtifactId; int AnalystId; //Employee performing analysis work on artifact […]

Method 'ExecuteAsync' does not have an implementation. EF Code First

This question already has an answer here: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation 3 answers

Should a large static table go in separate database?

I have a SQL Server 2012 table that is 100MB with 1 million records. This is static lookup table that would at the most change once per year. The only query is greater/less than on two columns to return a scalar. It is used in a standard ASP.Net web application, EF, IIS etc. Should I […]

Why is this Entity Framework LINQ query generating a slow where clause?

I was asked to investigate the cause of a poorly performing query in our database. I determined it was generated by a LINQ statement and tracked it to the source code and loaded that into linqpad. In Linqpad I displayed the generated SQL, shown below. As you can see, the first part of the WHERE […]

SQL Server : two foreign keys pointing to one table. Error: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

I’m getting the error: Msg 1785, Level 16, State 0, Line 238 Introducing FOREIGN KEY constraint ‘FK_Studios_Members_HeadId’ on table ‘Studios’ may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Below is a simplified version of the two tables I’m having problems […]

ASP.NET MVC 5 with Entity Framework 6 to existing database with model binding for some tables

I have a SQL Server database with more than 50 tables. It was used for my web application written in ASP.NET. Now I write a new ASP.NET MVC 5 web application for new functions under the original web application folder. I create some models (about 10 tables) with code first migration enabled database. Now I […]

Adding 'GO' statements to Entity Framework migrations

So I have an application with a ton of migrations made by Entity framework. We want to get a script for all the migrations at once and using the -Script tag does work fine. However…it does not add GO statements in the SQL giving us problems like Alter view should be the first statement in […]

Entity Framework updates local database, but update script gives an error when applied to production

I have a local dev environment and database that I update automatically with Update-Database, and then apply the migrations to the production environment with scripts (produced with Update-Database -Script). In my latest update, I added a new column, and then in the Up() method of the migration, I added the necessary code to populate the […]

Automatically link objects using computation on fields with Entity Framework or SQL Server

I have two “entities”, Job Code and Job Family: public class JobCode{ public int Code {get;set;} public string Name {get;set;} } public class JobFamily{ public int Code {get;set;} public string Name {get;set;} } JobCode.Code is a 5-digit code, and JobFamily.Code is 2 digits, which correspond with the first 2 digits of a Job Code, so […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.