Tag: entity-framework

EF select is not getting record

I have a large project with lots of data access going on. I just added a new table (from db) and the standard EF query is not working, but a sql query works. Here’s the data access: public Topic GetTopicByName(string name) … name value is KboInterestingTopic { var topics = from t in _db.Topics where […]

Entity Framework : Unable to change DataSource for Code First Migrations

I am working on a project where I am using Entity Framework along with code first migrations to update my database. I started this project on another machine and it worked out very well. Now I checked out the code on another machine. Since this machine does not have the database, I ran update-database command […]

Entity Framework One-to-one or zero – Database first

I’m trying to create a setup where I have different entities (e.g. User and Customer). Each of these entities have some Login-information which I store in a Login-table to avoid having to do duplicate work on the different entities requiring Login-data. However – I can’t get the setup to work using Entity Framework. I hope […]

How to drop and recreate indexes without growing the transaction log

I wanted to change a field in a database table to be a calculated field rather than being populated using a trigger. I am using Entity Framework database first so I added this sql to a migration to carry out the task: EXECUTE(‘ALTER TABLE [dbo].[BaseAnsweredQuestions] DROP COLUMN [CalculatedDueDate] ‘) EXECUTE(‘ALTER TABLE dbo.BaseAnsweredQuestions ADD CalculatedDueDate AS […]

Changing ntext to nvarchar using C# and Entity Framework

I have to add sorting to existing database created in SQL Server. The problem is that this database contains ntext columns that are not supported by LinQ’s OrderBy method. The database was written in a code-first approach, so I have access to template of database, but I can’t look at ready database working on the […]

Linq to SQL 2016 Stored Procedure OFFSET FETCH NEXT incorrect return type

I have an interesting issue that has kept me googling for a couple of days. I am executing a stored store procedure that implements Offset Fetch Next for custom .net paging. The entity framework can’t seem to figure out the correct return type. It thinks I am trying to return an int instead of a […]

Accessing virtual child object executes sql without WHERE clause

I have tried to research why, what I believe should be a relatively straightforward concept, is not working as expected. From what I have read the following should work in the way I expect, but it isn’t. I am retrieving data from an SQL database using entity framework, however I cannot get Lazy / Deferred […]

Identity mapping to a view with Entity Framework

It’s a common enough problem: you have a view that contains no primary key identifier, or even any combination of columns that guarantees each row to be unique. And you want to use this view in Entity Framework. What do you do? It’s been suggested that you modify the view to add a generated primary […]

EFInteractiveViews With Unit Of Work Raise An Exception Second Run

I have a big MVC & EF6 project. I have decided to use EFInteractiveViews to Pre-Generated views. But it’s raise “MappingViewCacheFactory is already set and cannot be modified.” exception at second run. How can i solve this problem? Thanks private MyContext _context; public UnitOfWork() { _context = new MyContext(); InteractiveViews .SetViewCacheFactory(_context, new SqlServerViewCacheFactory(_context.Database.Connection.ConnectionString)); }

Entity Framework self referencing primary key on insert

I am using entity framework and I have a scenario where I was handed down a database that is not designed properly and I cannot make any modifications to it, so please bare with me. When I insert a new record and it auto generates an auto identity value. I then have to subsequently update […]

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