0
엔티티 프레임 워크 사용 텍스트 상자에 표시 할 문자열을 선택하는 방법은 무엇입니까? 나는 다음을 수행 할 과거에 myReader 사용 :EF의 텍스트 상자에 표시 할 문자열 선택
while (myReader.Read())
{
string sName = myReader.GetString(1);
txtName.Text = sName;
}
엔티티 프레임 워크 사용 텍스트 상자에 표시 할 문자열을 선택하는 방법은 무엇입니까? 나는 다음을 수행 할 과거에 myReader 사용 :EF의 텍스트 상자에 표시 할 문자열 선택
while (myReader.Read())
{
string sName = myReader.GetString(1);
txtName.Text = sName;
}
당신은 텍스트 상자에 개체의 속성을 지정 욕망과보다 엔티티 (= 표)를로드 할 수 있습니다.
뭔가 같은 :
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;
}