Questions tagged [dbset]

224 questions
2
votes
1 answer

Entity Framework dbset not finding added entity

I am having an issue understanding why when adding a new entity to a DbSet of ObjectContext, that entity is not found will looking it up again. using (var db = new SmartrailDB()) { var cart01 = db.Carts.SingleOrDefault(x =>…
Michael Smit
  • 51
  • 1
  • 7
2
votes
1 answer

Many domain models sharing one data context in EF 5

I recently, out of ignorance and lack of time, merged the domain models (POCO entity classes) from several projects into one 'DataModel' project, because I didn't want to duplicate dedicated DbContexts over all the projects. It struck me as ideal…
ProfK
  • 49,207
  • 121
  • 399
  • 775
2
votes
1 answer

EF Code First not creating tables

I am using Entity Framework 5 (4.4.0) for .NET 4 I have a model created in code, as I did with several others. When I run my application, it creates the database, but does not create any tables. After that the application, exits with no error…
Ruben Alves
  • 41
  • 1
  • 3
2
votes
1 answer

C#, MVC3, How to use the non-generic DBSet with a runtime defined type?

I'm new to MVC and the EF. My app is a simple code-first with several POCO classes and a DBContext like this: public class ExpDefContext : DbContext { public DbSet Experiments { get; set; } public DbSet
2
votes
1 answer

Linq Expressions: Create a max query using a generic DbSet

In order to simplify creating fake data for unit testing, I want to have a function that can create a generic Entity (which I use as an underlying object for a lot of other classes). The entity has an index, and, for generating a new index, I want…
The Jonas Persson
  • 1,726
  • 1
  • 17
  • 36
1
vote
1 answer

How do I fix `System.MissingMethodException: Constructor on type Microsoft.EntityFrameworkCore.DbSet`1 not found.`?

Database Table Export to CSV using EntityFramework DbContext .NET 6 I have been tasked to create a Blazor ASP.NET Core application that will export each table from an MS SQL Server database into it's own .csv file. I have extracted the DbSets from…
Tyson Gibby
  • 2,590
  • 2
  • 18
  • 37
1
vote
1 answer

IEntityTypeConfiguration & DbSet definition for entities with Generic Type Parameters: Entity

I'm trying to write a generic IEntityTypeConfiguration for an entity that has a generic type parameter. I have the following class: public class ItemSpecs : Entity, IItemSpecs where TItemConstitution : Enum …
BHANG
  • 354
  • 1
  • 5
  • 16
1
vote
2 answers

How to abstract a EntityFramework Core DBSet within an interface?

I am using EF Core 6, and my DbContext looks like this : public class SpaceBattlesDatabase: DbContext, ISpaceBattlesDataBase { public DbSet Buildings => Set(); // + other irrelevant code } I would like to abstract it…
1
vote
1 answer

Is there a way to dynamically add a DbSet to EF core and to use Linq against the dynamic DbSet?

I'm using EF Core v. 5.0 and SQLite DB and I'm trying to dynamically add a DbSet to my DbContext. I have followed and readapted this guide to EF Core: https://romiller.com/2012/03/26/dynamically-building-a-model-with-code-first/ and I realized this…
1
vote
1 answer

DbSet not included in the ApplicationDbContext but a table is still created

I did not specify the DbSet in my applicationdbcontext. However, I am able to create order payments using the following method: public List Create(CreateOrderPaymentDto createInput) { if (createInput == null) return…
grozdeto
  • 1,201
  • 1
  • 13
  • 34
1
vote
1 answer

Unable to identify where to enable the FirstOrDefaultAsync method for a ASP.NET Core model

I'm having difficulty identifying where in a ASP.NET Core app we specify that a model can have the FirstOrDefaultAsync method enabled. I've previously scaffolded two models to razor pages, and for those I can write async method like so: component =…
1
vote
0 answers

Best Way to Manage Image Collections in Client-Side Blazor

I want to build a scrolling image collection, and I have a few ideas about how to go about it. I've gone down a few incorrect paths and had to backtrack, so I thought I'd open up my current plan in case someone could give me the benefit of their…
1
vote
1 answer

Joining tables in two separate databases with .Net Core 2.1 / EF Core

I have a .Net Core 2.1 Web API which talks to two MySQL databases. Therefore I have two DbContexts, each with a connection string pointing to the relevant database. In one of my controller actions, I need to return data which requires a join between…
Fabricio Rodriguez
  • 3,769
  • 11
  • 48
  • 101
1
vote
2 answers

Why is RemoveRange not clearing DbSet?

I have the following extension method for clearing DbSet: public static void Clear(this DbSet dbSet) { dbSet.RemoveRange(dbSet); } And the usage looks like this: databaseContext.Users.Clear(); databaseContext.SaveChanges(); Now the…
DomJourneyman
  • 65
  • 2
  • 9
1
vote
4 answers

Get Row Count of Dbset in DbContext dynamicly

I have a form that pass a instance of my DbContext and a Entity of Table to it as below : public frm_foo(DbContext DatabaseContext, DbSet TableEntity) { InitializeComponent(); var res…
Ali
  • 3,373
  • 5
  • 42
  • 54