c# - Refresh EntityDBContext to reflect current entries in database at runtime -


objective: have database , entitymodel configured in database first fashion. database has single table called records. make changes database, create new entitydb context, , iterate through each record in records. here's condensed version of flow:

var databasebuilder = new studentdatabasebuilder(database, dbdatasource);  databasebuilder.populatedatafromsource();  console.writeline($"{databasebuilder.studentsread} students sucessfully processed");    //this class autmoatically created wizzard, inherits dbcontext var model = new entitymodelconnection();   foreach (record g in model.records) {     console.writeline(g); } 

problem: gets output contents of database whenever application loads, not state it's in when entitymodelconnection made, , printing performed. if have database 5 entries, add 10 through sqlconnection/sqlcommand, i'll print out 5 entries. if run program again , erase everything, print entries, i'll 15 entries wanted last time, , on.

things tried: entityconnection changetracker.detectchanges, re-initializing new entityconnection.

summary: how entitydatabasecontext reassoicate underlying database such table record reflects current state of database.

let me know if need clarify things further. added detail, here copy of i'm calling entitymodelconnection():

public partial class entitymodelconnection : dbcontext {     public entitymodelconnection()         : base("name=entitymodelconnection")     {     }      protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         throw new unintentionalcodefirstexception();     }      public virtual dbset<record> records { get; set; } } 


Comments

Popular posts from this blog

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -