Questions tagged [dbset]
224 questions
7
votes
2 answers
Confusing articles and documentation about the differences (if any) between System.Data.EntityState.Add & DbSet.Add
I am working on a C# ASP.NET MVC 5 web application with EF 5. Mapping of my database tables using EF generates a DbContext class and an .edmx file. Today, I was reading a great article about creating generic DAL classes, but I stopped on the…
user1404577
7
votes
1 answer
Using DbSet.Local Property in Entity Framework
Following MSDN documentation we can use Local property to get local/cached data directly from the context without additional requests to a data source:
Gets an ObservableCollection that represents a local view of all Added, Unchanged, and Modified…

Kryszal
- 1,663
- 14
- 20
7
votes
1 answer
Converting an IQueryable to a DbSet
I'm not sure that this is possible, but I'm trying to unit test a repository that uses a DbSet. I thought the easiest solution would just be to make an Enumerable, and replace the DbSet with that, this is my attempt.
I'm using C#, EntityFramework,…

Kyle Gobel
- 5,530
- 9
- 45
- 68
6
votes
2 answers
What steps to get rid of Collection was modified; enumeration operation may not execute. Error?
Our programming involves some Mock testing using In-Memory Data. Therefore, we implemented the following code that would first create In-Memory Data of Customer objects
// Let us create some in-memory data
// Create a list of…

CS Lewis
- 489
- 8
- 30
6
votes
1 answer
How DbContext initializes automatic DbSet properties?
Consider the following class:
class MyContext : DbContext
{
public DbSet Orders { get; set; }
}
and instantiating a new object:
var mycontext = new MyContext();
Why mycontext.Orders is not null? When it was initialized? Who has…

Alireza
- 10,237
- 6
- 43
- 59
5
votes
2 answers
Moq DbSet NotImplementedException
I have a Moq DbSet that has been working until recently, however since the last update of dependencies it keeps throwing a NotImplementedException on IQueryable.Provider
Code used as follows:
var mockSet = new Mock>();
var list = new…

Kanadaj
- 962
- 9
- 25
5
votes
1 answer
DbSet.Add() not working
I have a class like this:
[Table("member_activation")]
public partial class MemberActivation
{
[Key]
public Int64 member_id { get; set; }
public String token { get; set; }
}
My db:
public class SMADbContext : DbContext
{
public…

user3861672
- 55
- 1
- 1
- 5
5
votes
1 answer
Entity framework: how to extend DbSet?
I am trying to define my own DbSet, like:
public class MyDbSet : DbSet
where TEntity : class
{
public override TEntity Add(TEntity entity)
{
....
And use it in DbContext
public MyDbSet Users { get; set;…

user3346850
- 254
- 4
- 17
5
votes
4 answers
Inherits from DbSet with the purposes to add property
Is there a way to inherits from DbSet? I want to add some new properties, like this:
public class PersonSet : DbSet
{
public int MyProperty { get; set; }
}
But I don't know how to instantiate it in my DbContext
public partial MyContext…

Alexandre TRINDADE
- 917
- 10
- 21
4
votes
1 answer
Dynamic query building with entity framework core - Build a query "by steps"
I'm trying to make a class to perform a dynamic filters, depending on what parameters I'll send to its "filter" method but I'm facing some difficulties on building my query.
It's more easy to explain with my following code, where I'm simply trying…
user9557542
4
votes
0 answers
How can I use an Entity Framework class type that is created at runtime?
I have used "code first from db" to create an entity class and include it as the type for a DbSet in a DbContext.
But I now have a new problem. I need to build an entity class at runtime that represents a row from an Oracle table/view and then use…

DLipkie
- 111
- 5
4
votes
1 answer
EF get dbset name in runtime from Type
Purpose:
I need to get the name of the dbset name of the entity
typeof(UserAccount) = "UserAccounts".
But in runtime I need a common type for the loop and therefor do not know example "UserAccount".
Only the "name" from typeof?
I have created an…

pladekusken
- 140
- 2
- 7
4
votes
2 answers
Must I create explicit DbSet properties on my DbContext?
I'm using Entity Framework 6 Code First with an Empty Database. I've created a fairly large number of POCO classes with a reasonably complex class hierarchy (a fair number of abstract classes and quite a few concrete classes). I'd like to be able…

Matt Knowles
- 387
- 2
- 12
4
votes
2 answers
EF6: Include Navigation Properties in DbSet.Local
I am loading data from an external source as xml, it gets deserialized and then I loop over the object to funnel them into my domain entities.
In order to create the relationships between data and cut down on database calls I wrote an extension…

jmichas
- 1,139
- 1
- 10
- 21
4
votes
1 answer
Short lived DbContext in WPF application reasonable?
In his book on DbContext, @RowanMiller shows how to use the DbSet.Local property to avoid 1.) unnecessary roundtrips to the database and 2.) passing around collections (created with e.g. ToList()) in the application (page 24). I then tried to follow…

juniper
- 311
- 5
- 13