Questions tagged [dbset]

224 questions
0
votes
1 answer

DbContext EntitySet null when entities are set to internal access

I want the db set to be internal in order to ensure external packages only have access to and program against the interface not the concrete class e.g. namespace Domain { public interface IProduct { string Description { get; } …
0
votes
1 answer

MVC 4: passing single inherited models into the main model to a partial view

Am trying to figure this out. I have a major class called Foods. I have multiple classes that inherit from Food: Pizza, Sandwich, Meals etc... I created the database using Code First Approach. The database has tables for Pizza, Sandwich and…
0
votes
0 answers

Perfomance issue - .Count in MVC view

For several pages I use a .Count inside a foreach loop @model ICollection foreach(var item in Model) { @item.Flight.FlightReservations.count } Because of lazy loading the EF makes a round trip to the database for this. Now I want to fix…
0
votes
1 answer

Saving data in multiple database sets

I have a database context with multiple database set. I have an edit (httpget) and an edit (httppost) method. I want to save specific data in specific datasets. How can I specify which database set I want to use? BTW, the view from of the Edit…
jpo
  • 3,959
  • 20
  • 59
  • 102
0
votes
1 answer

Find an entity using its Unique Key

In my asp.net mvc 3 application, I have a generic Repository. I use the Find method of the DbSet class to find an entity by its Primary Key, like here: private DbSet _dbSet; public T FindByID(object id) { return _dbSet.Find(id); } Is there…
ataravati
  • 8,891
  • 9
  • 57
  • 89
0
votes
1 answer

Some stupid situation about PK in C#: MVC3 can't insert a new record with passed PK and try to insert NULL as Primary key

Good day. I have MSSQL2008 database. And I made a proper model for one of the existing table (VLANs). public DbSet VLANs { get; set; } VLAN Model has field: [Key][Required] public int VLAN_ID { get; set; } //in the "VLAN" table it is…
-1
votes
1 answer

ASP.NET Core 5 DbSet totable

I am converting from EF6 to ASP.NET Core 5. Like many, I am confounded trying to migrate a DB from EF to Core. This is my own db, not Identity. Identity seems to be a different can of worms for db migration. I think my biggest problem when trying…
Bob Koury
  • 273
  • 3
  • 10
-1
votes
1 answer

Why is only one table created?

I use one model for several tables, but when I create the tables, only one of them is created. Why is that and can it be changed? public DbSet Champagne_TBL { get; set; } public DbSet Gin_TBL {…
JdDEV
  • 43
  • 5
-1
votes
1 answer

Change DbSet with table name

I would like to know how to change DbSet on a DbContext using a table name (instead of using a fix DbSet as in the example). I've tried this solution but with no results. var type = Assembly.GetExecutingAssembly() .GetTypes() …
Massimo Variolo
  • 4,669
  • 6
  • 38
  • 64
-1
votes
1 answer

Entity Framework DbSet performance usage

Having an DbContex: public class ProductsContext : DbContext { public DbSet Products; } I can do this: Product product = _context.Products.Find(1); I want to do that in an generic way IDbSet set = _context.Set(); T entity…
ramaral
  • 6,149
  • 4
  • 34
  • 57
-1
votes
1 answer

Entity framework call stored procedure with parametr

I need get list of class properies. Code fragment: DbSet query = context.SomeClass; public partial class SomeClass { public decimal ID { get; set; } public string ModelName { get; set; } } I need get List, but I…
-2
votes
1 answer

FirstOrDefault in DbSet slow using Linq

I have this Linq expression (FirstOrDefault) and it's very slow. Options is an DbSet DbOption dbo = ctx.Options.FirstOrDefault(o => o.SynN == oLoaded.SynN && o.OwnerId == oLoaded.OwnerId && …
scorona85
  • 97
  • 6
-2
votes
2 answers

How can I get data from different DbSet entities and combine into one object?

When using Entity Framework 6, how is the most efficient way to create an object or objects with additional data from other DbSet entities, when I have a DbContext or IQueryable? Here is some code: If I have an Data class as follows: public class…
Simon
  • 7,991
  • 21
  • 83
  • 163
-3
votes
1 answer

MVC DbSet,base not solving

How can I solve the problem in the picture?
1 2 3
14
15