exception - Calling functions on Entities from a Context in C# -


i have started model-first , generated database, , i've created partial classes entities can perform operations on them.

my code in context getting long, redundant, , want able make calls, such as:

using (var db = new context()) { ...   db.myentity.computedistance(); ... }  ***added***  public void computedistance() {     int distance = 0;     myentity curr = this;     while (curr.parent != null) {         distance++;         curr = curr.parent;     }     this.distance = distance; } 

and can this, except whenever try navigate relational properties, run issues lazy loading hasn't populated variables, , few other types of exceptions. tried passing db functions, got bothersome want use function without using db. tried having db optional , create if didn't exist, still didn't work well.

it seems i'm doing wrong, , haven't found examples of how it.

how guys handle these situations, or, how avoid them?

please let me know if need more detail, thanks!

i've played around bit more, , realized must have been storing element previous instance of context. i've made sure don't use elements context has been disposed , seems working.

thanks help.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -