Questions tagged [dbset]
224 questions
4
votes
1 answer
Get DbContext from DbSet
I am developing some extensions methods to add some funcionalities for DbSet. However, when creating an "Update" method, I need the DbSet's DbContext to be able to modify the state of a entity. The current implementation:
public void…

Arthur Nunes
- 6,718
- 7
- 33
- 46
3
votes
2 answers
System.Linq.Dynamic.ParseException: 'Operator '>' incompatible with operand types 'DateTime?' and 'Int32''
How can I correctly parse sdate ?
IQueryable bddata = Junior2KepwareContext.Set(type)
.Where($"C_NUMERICID == {idLinea}")
.Where("C_TIMESTAMP > "+ startDate )
.OrderBy("C_TIMESTAMP");
System.Linq.Dynamic.ParseException:…

Massimo Variolo
- 4,669
- 6
- 38
- 64
3
votes
2 answers
X is a variable but used like a type when trying to cast
I am passing a string of the name of the entity type I want to query and getting the type based on the string. I want to get the DbSet back and return an IQueryable. The problem is where I am doing (DbSet) and getting the following…

Kogroth
- 87
- 1
- 2
- 8
3
votes
1 answer
Use where clause in dynamic dbset in Entity Framework
Currently I am using the following code block to create DbSet dynamically and retrieve data from it -
Type entityType = Type.GetType("MyProject.Models."+ EntityName + ", SkyTracker");
DbSet mySet = Db.Set(entityType);
foreach (var entity in…

s.k.paul
- 7,099
- 28
- 93
- 168
3
votes
1 answer
Filtering non-generic DbSet with dynamically built Expression
Plot:
I have a class implemented as a facade around Entity Framework DB context. It developed to maintain backward compatibility, it mimics class with same public interface, but uses DTOs instead of EF entities.
Problem:
I have next method inside…

Andrey Weber
- 57
- 3
3
votes
1 answer
Reload all related objects / navigation properties with Entity Framework DbContext DbSet
I currently have:
context.Entry(employee).Reload();
context.Entry(employee).Reference(p => p.Manager).Load();
context.Entry(employee).Reference(p => p.Department).Load();
I wish to load all related entities without specifying them individually.…

pfeds
- 2,183
- 4
- 32
- 48
3
votes
2 answers
Mocking DbSet inline
I am using .NET4.5, EF6, and Moq for unit testing. I am trying to mock up some Db data for test. I have an example how to do this with declaring mockset as variable and then using mocks.
public static class TestExtensionMethods
{
public…

Matas Vaitkevicius
- 58,075
- 31
- 238
- 265
3
votes
2 answers
Entity Framework - Database First - Invalid column name error
I have three simple classes and I am wiring up EF6 to an existing database.
Classes are as follows
namespace Infrastructure.Models
{
[Table("Applications")]
public class Application
{
[Key]
…

Solo812
- 401
- 1
- 8
- 19
3
votes
2 answers
Get the primary key column from dbSet
I want to write a function, which receives any Entity object and finds the current value by automatically determined primary key and updates it.
Could you please point me any direction.
public void Update(object entity)
{
using (var _db =…

Vahagn
- 386
- 2
- 21
3
votes
1 answer
Manipulating objects with DbSet and IQueryable with NSubstitute returns error
I'd like to use NSubstitute to unit test Entity Framework 6.x by mocking DbSet. Fortunately, Scott Xu provides a good unit testing library, EntityFramework.Testing.Moq using Moq. So, I modified his code to be suitable for NSubstitute and it's been…

justinyoo
- 2,123
- 1
- 21
- 24
3
votes
0 answers
EF TPT Inheritance: one DbSet per child?
In the MSDN they show how to implement EF TPT with this example:
public abstract class BillingDetail
{
public int BillingDetailId { get; set; }
public string Owner { get; set; }
public string Number { get; set; }
…

sports
- 7,851
- 14
- 72
- 129
3
votes
1 answer
FakeItEasy DbSet / IQueryable - Entity Framework 6
I was wondering if anyone had a similar example to this post for FakeItEasy (original post is here. I have been trying to find the correct setup, but could not get it right. I could not find any examples online. I am beginning to teach myself unit…

jmzagorski
- 1,135
- 18
- 42
3
votes
2 answers
ASP.MVC db Find(), but with non-primary key parameter
How does one get a list of results by using a key that is not the primary key? To be more specific, I have a composite primary key where I would like to retrieve all the matches with one column's parameter.
I would think, in an ActionResult in the…

user
- 61
- 1
- 1
- 8
3
votes
2 answers
Do ObjectContext and ObjectSet offer advantages over DbContext and DbSet?
I am currently finalizing the architecture of my new application that will be using Entity Framework as its ORM. However, I am a little bit confused with respect to whether I should go with the default option (DbSet and DbContext), or use a "tricky"…

Nirman
- 6,715
- 19
- 72
- 139
2
votes
2 answers
Non nullable property warning in DBcontext class for dbset property
I have my database context class as below
public class DataContext : DbContext
{
public DataContext(DbContextOptions options) : base(options)
{
}
public DbSet Customers;
public DbSet Orders;
}
it warns…

EagerToLearn
- 89
- 12