Tag: entity-framework

Get total row count in Entity Framework

I’m using Entity Framework to get the total row count for a table. I simply want the row count, no where clause or anything like that. The following query works, but is slow. It took about 7 seconds to return the count of 4475. My guess here is that it’s iterating through the entire table, […]

Entity Framework The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

On updating database in Entity Framework , Code first Migration, I am getting this error: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint “FK_dbo.Clients_dbo.MedicalGroups_MedicalGroupId”. The conflict occurred in database “hrbc”, table “dbo.MedicalGroups”, column ‘Id’. This is my class: public partial class Client { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public […]

Entity Framework 5 mixing Oracle & SQL Server

I have 2 data layer DLL projects. One is hitting Oracle tables and the other SQL Server. Each one works on their own when used in separate projects. When I make a project that includes both DLL’s I get the following error when an Oracle table is queried: Schema specified is not valid. Errors: Model.ssdl(2,48) […]

Dynamic query with OR conditions in Entity Framework

I am creating a creating an application that searches the database and allows the user to dynamically add any criteria (around 50 possible), much like the following SO question: Creating dynamic queries with entity framework. I currently have working a search that checks each criteria, and if it is not blank it adds it to […]

EF 6 vs EF 5 relative performance issue when deploying to IIS8

I have an MVC 4 application with EF 6. After upgrading from EF 5 to EF 6 I noticed a performance issue with one of my linq-entities queries. At first I was excited because on my development box I noticed a 50% improvement from EF 5 to EF 6. This query returns about 73,000 records. […]

System.Data.EntityException: The underlying provider failed on Commit

Using Entity Framework, I received a number of the following exceptions last night in one of my applications: System.Data.EntityException: The underlying provider failed on Commit. —> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, […]

Error in update-database command in code first migration

I am working on Desktop application in WPF and creating SqlRepository with LocalDB to store data. I am using following tools Visual Studio 2013 Community with update 2 Entity Framework 6.1.2 for Code first migration I have created local database with Microsoft SQL Server Database File (SqlClient) configuration. Database created successfully and below is connection […]

How do I set a column in SQL Server to varchar(max) using ASP.net EF Codefirst Data Annotations?

I’ve been searching around the web trying to figure out the right syntax to have Entity Framework Code First create my table with a column: varchar(max). This is what I have. By default this creates varchar(128). How do I create varchar(max)? I have tried [MaxLength] without success. Any help would be appreciated. Thanks! [Column(TypeName = […]

SQL Server database on Azure UNIQUE KEY constraint crash

After launching promo campaign of our software yesterday we’ve met some strange problems with our SQL Server database. This error occurs when users did signup for an account at our website. When it was low user traffic everything seemed to be ok and worked properly but once traffic increased to ~10 signups at a time […]

Multiple databases with slightly changing models. How do I allow `EF` to work with different database structures at run-time?

I am working with EF6, MSSQL, Oracle, .NET4.5 on a system that is used globally across company (many departments) to query different databases that belong to our department, that have mostly same EF model, some databases are Oracle and some are Microsoft SQL, some are development or uat, some are logs. I am using different […]

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