Questions tagged [dbset]
224 questions
2
votes
1 answer
Entity Framework Core FromSqlRaw mock test cases
I am creating a integration test for api method which have some query like below
public async static Task> ForSysAll(this DbSet dbSet,int id) where T : class
{
return await dbSet.FromSqlRaw($"SELECT * FROM dbo.TableName…

Bunty Choudhary
- 65
- 2
- 8
2
votes
2 answers
Creating Multiple Tables in DB Using Same Model in ASP.NET Core Razor App
I'm trying to make a Web App using ASP.NET Core Razor App.
While doing this, I have a trouble with creating some new tables.
Here is my ApplicationDbContext.cs file.
using System;
using System.Collections.Generic;
using…

Dongmin Seo
- 25
- 4
2
votes
1 answer
'((System.Linq.IQueryable)((Moq.Mock)(mockDbSet)).Object).Provider' threw an exception of type 'System.NotImplementedException'
I am attempting to mock multiple DbSets and their DbContext. I'm stumped about this one. I appreciate any feedback.
When I run the test, I receive the following null reference exception:
System.NullReferenceException : Object reference not set…

Thor
- 181
- 1
- 2
- 8
2
votes
2 answers
In C#, is there a generic way to pass a DBSet to a method?
I currently have the following working code:
private Converter RemoveAll(List databaseSet) {
databaseSet
.ForEach(item => this.myContext.Remove(item));
return this;
}
which I can…

Brian Kessler
- 2,187
- 6
- 28
- 58
2
votes
1 answer
DbSet.Local.Any() performance issue when upgraging EF Core from 2.2.6 to 3.1.3
There is a method which is responsible for returning a single GitCommit object based on its hash from our git commit cache database table. We use Entity Framework Core, and when I've upgraded the nuget packages from 2.2.6 to 3.1.3 I've realized a…

Gábor Almádi
- 125
- 2
- 6
2
votes
0 answers
DbUpdateConcurrencyException on Remove when trying to delete an entry from DbSet without loading it first
I'm trying to delete an entry without loading it from the DB first. I've tried tons of various approaches (all I managed to find in Internet), but none of them seem to work:
Database operation expected to affect 1 row(s) but actually affected 0…

efpies
- 3,625
- 6
- 34
- 45
2
votes
2 answers
How to query the DbSets of all types that implement an interface?
Many of my data models use this interface:
public interface IHasPrimaryImageProperty
{
PrimaryImageDataModel PrimaryImage { get; set; }
int? PrimaryImageId { get; set; }
}
Where PrimaryImageDataModel is:
public class…

Martin Hansen Lennox
- 2,837
- 2
- 23
- 64
2
votes
0 answers
Entity Framework Core 1.1.2's DbSet implementation
I am writing a new database provider for Entity Framework Core 1.1.2 (with target framework: .NET 4.5.2), and I have a very frustrating issue. My relevant installed NuGet packages…

Baros
- 53
- 5
2
votes
2 answers
Member 'CurrentValues' cannot be called for the entity of type 'MyTable' because the entity does not exist in the context
I have a MVC application that used Entity Framework v6.0. Whenever a change is made to the DbContext, I override the SaveChanges() method and record the modifications in an audit log. Below is code for part of the audit log recording process:
public…

Tot Zam
- 8,406
- 10
- 51
- 76
2
votes
2 answers
C# | Entity Framework | An item cannot be removed from a fixed size Array of type
In EF, I tried adding a record using syntax:
Context.Set().Add(TABLEROW)
I get this crazy error:
"An item cannot be removed from a fixed size Array of type"
I did a bit of goggling and it suggests I change from DBSet to List from the…

user532104
- 1,373
- 6
- 17
- 27
2
votes
0 answers
Identity 2.0 with existing Database - The entity types 'IdentityRole' and 'AspNetRoles' cannot share table 'AspNetRoles'
I've been working for a little over two weeks on implementing the ASP.Net Identity 2.0 system into an MVC 5 app using an existing database. It has been...trying.
Currently I'm fighting with an error in my registration modifications (and I fear that…

David
- 43
- 7
2
votes
1 answer
Update object using only DbSet
I'm trying to apply the unit of work pattern as described in this blog, but have bumped into the following problem: If I inject the associated DbSet into the repo only, e.g.
public ArticleRepository(DbSet articles)
{
this.articles =…

Thorsten Westheider
- 10,572
- 14
- 55
- 97
2
votes
0 answers
Using interfaces with entity framework 6
I have coded a C# MVC5 Internet application, and want to know if I can use interfaces with EF6, and if not, how else I should code my classes.
Here is what I have that does work:
public class TestObjectWithObjectList
{
[Key]
public int Id {…

Simon
- 7,991
- 21
- 83
- 163
2
votes
1 answer
Adapter pattern for IDbSet properties of a DbContext class
Is there a way to use the method described in this answer No FindAsync() method on IDbSet for DbSet properties of a DbContext?
Edit:
The answer linked contains a description how to build a interface inheriting from IDbSet and adding support for the…

musium
- 2,942
- 3
- 34
- 67
2
votes
1 answer
Execution of non-generic DbContext.Set?
I need to execute a dynamic set type, here's what I'm trying to do (pseudo):
var type = GetSetType(); //System.Type
var set = context.Set(type);
var results = set.ToArray();
I know this can't work for sure, Enumerable ex. methods are only for…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632