c# - Which approach to use on a provider with entity framework? -
i have class:
public class tool { [edmscalarpropertyattribute(entitykeyproperty=true, isnullable=false)] [datamemberattribute()] public int64 id { get; set; } [edmscalarpropertyattribute(entitykeyproperty=false, isnullable=false)] [datamemberattribute()] public string name { get; set; } }
my provider has 2 methods:
public ienumerable<tool> getfirst() { using (var db = new entitites()) { return db.tools.firstordefault(); } } public void update(tool o) { using (var db = new entities()) { db.tools.savechanges(); } }
it doesn't work because on different contexts, parameter on update
method not being used. can object database , change fields 1 one parameter object save changes.
what should do?
- update object , save?
- keep 1 context on providers?
- another approach?
i found attach
method another question, quite similar
using (var db = new entitites()) { // attach object on context db.attach(tool); // change state of context ensure update db.objectstatemanager.getobjectstateentry(tool).setmodified(); // clientwins, flawless victory db.refresh(refreshmode.clientwins, tool); }
Comments
Post a Comment