Questions tagged [dbset]

224 questions
1
vote
1 answer

Test DbSet with RhinoMock

I need to mock a DbSet with RhinoMock. I found a way to mock IDbSet, but not DbSet. I found a way with another mocking framework, but i have to use RhinoMock. Can somebody please translate it to rhino mock? I found this on…
Dosihris
  • 85
  • 1
  • 8
1
vote
1 answer

Initialize a DbSet without a Context in C# - Mocking

I'm writing a Test Cases for a Common generic methods, In that I don't have any database configuration, but the method generic method is handling the IQueryable object. So, I tried the following code public static DbSet GetPersonDbSet() { …
user7784919
1
vote
1 answer

Conditionally select between different DbContext.DbSet (as template-parameter)?

Scenario: I have an existing database where I operate on. I transform data and map them into new tables. To easy validation of these transformations I need to put them into seperate tables (prefixed with Test_). But I still need the functionality of…
user5997884
  • 157
  • 1
  • 9
1
vote
1 answer

Selecting from type-based DbSet using .Set() instead of .Set()

I am creating an advanced search that converts an OData expression into a .NET expression tree (Expression>). I pass this expression into my EF6 .Select() method as a predicate and it works as expected. However, in implementing this…
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
1
vote
2 answers

Entity Framework CodeFirst, Add Dbset to DbContext, programmatically

how can i Add DbSet to my dbContext class, programmatically. [ public class MyDBContext : DbContext { public MyDBContext() : base("MyCon") { …
Iman Salehi
  • 908
  • 2
  • 14
  • 34
1
vote
1 answer

Entity Framework - DbSet Contains Null Entity

I'm tyring to add an entity to DbSet and save changes in context in Entity Framework Code First. I have University DbSet: public DbSet Universities { get; set; } I have 5 class in use - Term; Faculty; Department; University; and…
Fethi Tekyaygil
  • 355
  • 2
  • 15
1
vote
0 answers

How to Use the DataSource OBJECT Option with a DBset DbContext Class?

I'm using EF7 and SQLite in a Windows Form Project with VS2013. I created a Context Class that inheretes DbContext and create a DbSet for each of these 3 classes that represent my tables. public DbSet Servers { get; set; } I inserted data…
1
vote
1 answer

Mocking database context class with DbSet instead of IDbSet in Entity Framework

I am developing an Asp.Net mvc application. I am doing unit testing to my application. I use Moq to mock objects. In my test I need to mock database context and its DbSets. I can mock database context and test. But the problem is I have to change…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
1
vote
1 answer

EF Code Structure in WinForms

I need some help with my code structure! I have a form with some mandatory fields and some optionals. I run some validation prior to saving the records on the database to make sure the data conforms to integrity rules. If its properly validated the…
1
vote
1 answer

How to access DbSet type dynamically

I'm using LINQ expressions in order to build select and where expressions dynamically. The select method looks like this: public Expression> GetSelectExpression() { ParameterExpression l_pe =…
1
vote
1 answer

Looping over derived DbContext DbSets so I can add a ClearAll() extension to my DbContext object

Based on [the difference between Type.IsGenericType and Type.IsGenericTypeDefinition][1], I gained the piece of information I was missing in order to be able to retrieve a DbContext's DbSets via Reflection. However, I am now stuck somewhere else.…
Veverke
  • 9,208
  • 4
  • 51
  • 95
1
vote
1 answer

EntityType has no key defined, despite using [Key]

I am configuring context in my application. These are throwing expection: public DbSet ApplicationUsers { get; set; } public DbSet Books { get; set; } It looks like this: BookList.Models.Book: : EntityType 'Book' has no key…
1
vote
0 answers

EF context behaving differently between IIS Express and IIS

Seeing a difference in behaviour between IIS Express (Visual studio debugging) and a locally installed IIS server (on my dev machine). Running the following code via visual studio debugging I get my expected result: internal void performTest() { …
Flick
  • 11
  • 2
1
vote
1 answer

How to pass Dbset object as a parameter to any user define function in entity framework code first?

I want to pass Dbset Object to my method. This is my Method: public static class MyClass { public static Floor ReturnObject(this DbSet floor, int Id) { var context = floor.passContext() as MyDBContext; …
1
vote
2 answers

Conversion of repository pattern class from c# to vb.net

I had the following c# code: public T Single(Expression> where) { return _dbset.Single(where); } I tried to convert this to vb.net using a conversion tool which rendered the code as follows: Public Function…
Jay
  • 3,012
  • 14
  • 48
  • 99