Questions tagged [dbset]

224 questions
0
votes
1 answer

MVC 5 - Multiple DbContexts in a controller

I am developing a MVC 5 internet application and I have a question in relation to having more than one DbContext class in a controller. My DbContext class has many DbSet objects for different model entities. None of my model entities are using…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

Why is the DBSet Add failing, and also destroying the existing Customer entries in the DBSet?

Our programming involves some Mock testing using In Memory Data. // Let us create some in-memory data // Create a list of Customer List listOfCustomers = new List() …
CS Lewis
  • 489
  • 8
  • 30
0
votes
1 answer

How to overload a method that has params object[] as parameter

Our database has a Primary Key defined on every table existing of a combined key with a short and an int. Therefore, using Entity Framework we can try to find an element by calling to it's Context.DbSet<>.Find(params object[] parameters) method. In…
0
votes
1 answer

EntityFramework - Cannot Delete Entity using DbSet

I am trying to delete an object from my database using EntityFramework's DbSet. The code is as follows: var dbObject = FindById(id); _masterDb.DbTable.Remove(dbObject); _masterDb.SaveChanges(); I get the following error: "The object cannot be…
COBOL
  • 1,031
  • 8
  • 16
  • 32
0
votes
0 answers

System.Entity.DbSet working mechanism in Entity Framework

I was wondering how DbSet actually sets itself. If you see the definition of DbSet, it is a concrete class. But all the methods are not implemented making it looks more like interface. public class DbSet : DbQuery, …
CodeSchool JJ
  • 585
  • 5
  • 16
0
votes
1 answer

EF6 foreign key constraint in simple model

I am coding a simple MVC 5 internet application. Here are my models: public class House { [Key] public int Id { get; set; } public string name { get; set; } public virtual ICollection rooms { get; set; } public int itemId {…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

How do I use the || operator in a lambda expression

How do I use the || (or) operator in a lambda expression? Here is what I have tried: db.assets.Where((u => u.userName.Equals(userName)) || (c => c.category.Equals("DefaultMapMarker")) Thanks in advance EDIT I am wanting to get a list of assets for…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
2 answers

DbSet<>.SqlQuery insert into several variable values

I'm working on a c# project and I have created a Database with EntityFramework. This is the Database: public partial class BDDInterneEntities : DbContext { public BDDInterneEntities() : base("name=BDDInterneEntities") { } …
Kraenys
  • 297
  • 1
  • 5
  • 19
0
votes
1 answer

ASP MVC / EF6 - Automatic logging

Every table of my database has got 2 columns at the end, which allows logging (User who made the action, and Date of the action). EDIT : I use Code-First migrations. So I would like those two logging columns to be filled automatically : Each time I…
Glad
  • 147
  • 1
  • 11
0
votes
1 answer

UnitTesting EF6 with OfType

I am trying to follow the guidelines provided http://msdn.microsoft.com/en-us/library/dn314429.aspx by Microsoft for Unittesting DbSets. All was going well - as they documented. Until I got to some code which works with a inheritance table. Since…
0
votes
1 answer

Delete a DbSet object that has containing DbSet objects

I have coded a C# MVC5 internet application, where I have a MapCompany object that has a List. I have a DbSet as well as a DbSet. When I call the Delete Action result when trying to delete a MapCompany object, I…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

Accessing an extension method on a dbset subtype

I have an extension method defined as: public static class CurrentItemExtensions { static GPOPricingEntities ctx = new GPOPricingEntities(); public static List Get(this DbSet item, int tierId, string contractId) …
0
votes
0 answers

Entity Framework: Replacing an entire DbSet collection

I have a generic class that performs add/update on entities of type T. The AddOrUpdate() method takes in a DbSet collection to act on as well as a list of items to add or update in the DbSet. The ItemExists() is used to check to see if an item…
Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82
0
votes
3 answers

Should I have one or two DbSets?

I am coding an MVC5 C# Internet application and I have a class called MapCompany and a class classed MapLocation. Each MapCompany has a list of MapCompany's. My question is, for the context class, should I just have a DbSet, and add…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

How to use a DbSet with a generic type

I have an interface: public interface ILanguageEntity { int Id { get; set; } string Name { get; set; } string Code { get; set; } string Culture { get; set; } string LocalName { get; set; } bool IsRightToLeft { get; set;…
Saeed Hamed
  • 732
  • 2
  • 10
  • 28