2013-10-30 59 views

回答

0

您必須加載實體(=表),你的願望,比實體的屬性分配給該文本框。

喜歡的東西:

using (var myContext = new EntityContext()) 
{ 
myContext.TableName.Load(); //this will load all rows from the table 

var list = myContext.TableName.Local; //.Local is a list of the entities which gets populated when you cann the Load() method 

//now you can either enumarte your list like so 
foreach (TableName item in list) 
{ 
string sName = item.PropertyName; //PropertyName is the property you want to display, this would be like using not an index in myReader.GetString(1) but the columnname myReader.GetString("ColumnName") 
txtName.Text = sName; 
} 

//or if you want to get a certain item out of your list you can use LINQ/MethodChains 
//MethodChain 
var item = list.First(x => x.PropertyName == "HelloWorld!"); 
string sName = item.PropertyName; 
txtName.Text = sName; 

//LINQ 
var item = (from x in list 
      where x.PropertyName == "HelloWorld!" 
      select x).First(); 

string sName = item.PropertyName; 
txtName.Text = sName; 

//the methodchain and linq is a "new" technology that simplifies this code (which does the same) 
TableName item = null; 
foreach (TableName tempItem in list) 
{ 
    if (tempItem.PropertyName == "HelloWorld!") 
    { 
     item = tempItem; 
     break; 
    } 
} 

string sName = item.PropertyName; 
txtName.Text = sName; 

}

相關問題