Tag: entity-framework

Entity Framework – Prevent Cache in Context

I have a Entity Framework based Web API that reads and write data into Mssql Database. Context is great if you don’t want to access database each time you want to access any data, because it is caching the data that you used before. But my problem sarts here; I have an crawler that works […]

Foreign Key on Code First Migration That Shouldn't Be There

I have 2 models currently that I need to run a migration for into a new database, and I’m not getting the structure that I’m expecting. I apologize if this is an easy answer, I’m fairly new to Code First with Entity Framework. First I have a User object. This just should have a UserID […]

How to change datatype of foreign key in EF code-first

I have two models public class ContractType { public Guid ContractTypeId { get; set; } public string Name { get; set; } } public class JobPost : BasePost { public ContractType ContractType { get; set; } public Guid ContractTypeId { get; set; } } As you can see ContractTypeId is a foreign key in JobPost […]

High concurrency upserts cause deadlocks and query time of > 30s

I’m working on an application which uses EF6 for most database operations, and for the most part the database stuff is non-critical and isn’t under a lot of load. There is one exception to this rule, where we have a stream of possibly 100/s events coming in which need to insert or update a row […]

What is “The underlying provider failed on EnlistTransaction” Error in SQL?

I am having an application hosted in the IIS. My IIS and SQL were in difference systems.Using a single TransactionScope I am inserting into three different tables using Entity framework. Now I am getting the following error. “The underlying provider failed on EnlistTransaction” which have the inner exception as “Network access for Distributed Transaction Manager […]

Entity Framework Code First setting Isolation Level by query

Sometimes you need READ UNCOMMITTED or (NOLOCK) but only when you need a quick snapshot over some non-critical data. There are many ways to set this but all methods apply to when the sql LINQ is being materialized. However, in my app I need to run several queries in parallel. They are actually being passed […]

Weird “Cannot use a CONTAINS or FREETEXT predicate on column 'Name' because it is not full-text indexed.” error

I have followed the article here to implement Full text search with entity framework. I have 2 search boxes in my form. One for search can be used for name and number and the other search box is used to search for address. Some a weird error message I get from the sql server as […]

EF 6 Code First 1 to 1 Mapping, avoiding a seemingly needless LEFT JOIN

Update: I should have said I’m doing database-first, and have inherited a database with some bad design. The schema is fixed and cannot be changed. I have a Call table, and a Message table. The idea is that a Message can be created from a Call or from somewhere else (maybe a web site). So […]

How can I load entities with complex types from a table-valued function?

I have a table-valued function that returns entities that contain complex types. I am trying to figure out the best way to load this data into my code-first application as entities. I tried the Code First Functions project, but it doesn’t support entities with complex types. I also tried SqlQuery, e.g., context.MyEntities.SqlQuery(“SELECT * FROM [TableValuedFunction]()”) […]

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar while executing a stored procedure with Entity Framework

I am getting error that procedure expects parameter ‘@statement’ of type ‘ntext/nchar/nvarchar while executing a stored procedure with Entity Framework. This is my stored prodecure: Create Procedure [dbo].[usp_RolesList] (@WhereCond varchar(50)) AS Begin Set NoCount ON Declare @SQLQuery AS Varchar(max) Set @SQLQuery = ‘Select * From dbo.AspNetRoles ‘ + @WhereCond Execute sp_Executesql @SQLQuery End and this […]

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