c# - ADO.NET Entity Framework in WPF MVVM? -


i'm beginner wpf & mvvm.

i have view datagrid. i've set datacontext view model & set binding ibindinglist. model consists of ado.net edmx.

i'm querying ef table viewmodel using linq. seems query has in method avoid error 'a field initializer cannot reference non-static field, method, or property 'entity_mvvm.viewmodels. etc.'

so here code queries ef table ibindinglist. how invoke getdata method expose query results in view?

namespace entity_mvvm.viewmodels   public class contractviewmodel : inotifypropertychanged   {     public void getdata()    {        ldbentities db = new ldbentities();         ibindinglist contracts = ((from c in db.tbcontracts                                   select new { c.contract_id, c.contract_name, c.country }      ) ilistsource).getlist() ibindinglist;     }     public event propertychangedeventhandler propertychanged;  } } 

thanks all

instance vairable cannot used initialize varible ,since compiler may not execute in same order.

try moving ldbentities db = new ldbentities() view model constructor.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -