ãšã³ããªãŒ
ãããã®ãšã³ãã£ãã£ãWinFormsã³ã³ãããŒã«ã«ãã€ã³ãããããšã«å°å¿µãã Bernardo Castilho ã«ããèšäºã®ç¿»èš³ã«æ³šç®ããŸãã ç§ãšåæ§ã«ããã®èšäºãããªãã«ã圹ç«ã€ããšãé¡ã£ãŠããŸãã
- ããŠã³ããŒãäŸïŒEF4ãCïŒïŒ-1.03 MB
- ããŠã³ããŒãäŸïŒEF4ãCïŒãUIã¬ã€ã€ãŒããããŒã¿ã¬ã€ã€ãŒãåé¢ïŒ-120 KB
- ããŠã³ããŒãäŸïŒEF4ãVBãMr 'VBForever'æäŸïŒ-946 KB
- ããŠã³ããŒãäŸïŒEF5ãCïŒïŒ-1.3 MB
- ããŠã³ããŒãäŸïŒEF6 CïŒïŒ= 1.3 MB
ä»æ¥ãWinformsã¯äŸç¶ãšããŠå€ãã®ããŒã¿æåããžãã¹ã¢ããªã±ãŒã·ã§ã³ã®ãã©ãããã©ãŒã ã§ãããããŒã¿ãã€ã³ãã£ã³ã°ã¯Winformséçºã®äžå¯æ¬ ãªéšåã§ãã ããŒã¿ãåŠçããããã«æšæºã®ADO.NETã¯ã©ã¹ã䜿çšããå ŽåãDataSetã¯ã©ã¹ãäœæãããããã®ã¯ã©ã¹ãDataSource ã DataMemberããŸãã¯Bindingããããã£ã䜿çšããŠèšèšæã«ãã€ã³ãããããã«äœ¿çšãããããŒã«ã«ç²ŸéããŠããŸãã
æªããã¥ãŒã¹ã¯ããããã®è±å¯ãªéçºæ©èœãEntity FrameworkããŒã¿ãœãŒã¹ã«é©çšã§ããªãããšã§ãã ç°¡åãªãã€ã³ãã£ã³ã°ã§ããã³ãŒããæžãå¿ èŠããããŸãã åäœããåºæ¬çãªãã€ã³ãã£ã³ã°ãååŸããã«ã¯ãå°ãã®ã³ãŒãã§ååã§ãããæ £ããŠããå®å šãªãã€ã³ãã£ã³ã°ïŒèªåãœãŒãããã£ã«ã¿ãªã³ã°ãéå±€ãã€ã³ãã£ã³ã°ãªã©ïŒãååŸããã«ã¯ãããªãã®äœæ¥ãå¿ èŠã§ãã
幞ããªããšã«ã EFWinFormsã©ã€ãã©ãªã䜿çšãããšãããŒã¿ãã€ã³ãã£ã³ã°ãç°¡åã«å®è¡ãã Winformsã§ããŒã¿ãã€ã³ãã£ã³ã°çšã®åå©çšå¯èœãªã³ã³ããŒãã³ããäœæã§ããŸãã ã©ã€ãã©ãªã«ã¯2ã€ã®ã³ã³ããŒãã³ãããããŸãã
- EntityDataSource ïŒããŒã¿ãšã³ãã£ãã£ã¢ãã«ãã«ãã»ã«åãããã®èŠçŽ ããã€ã³ãã£ã³ã°ã«é©ããããŒã¿ãœãŒã¹ãšããŠæ瀺ããã³ã³ããŒãã³ããéçºäžã«å®å
šã«ãµããŒããããŸãã
- EntityBindingNavigator ïŒè¡šç€ºçšã®ããã²ãŒã·ã§ã³ãæäŸãããšã³ããªã®è¿œå ãšåé€ãããŒã¿ããŒã¹ãžã®å€æŽã®ä¿åãŸãã¯åŸ©åž°ã®ããã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããã³ã³ãããŒã«ã
EntityDataSourceã³ã³ããŒãã³ã
EntityDataSourceã³ã³ããŒãã³ãã¯ãæšæºã®ADO.NETããã°ã©ãã³ã°ã§DataSetããã³BindingSourceã®åœ¹å²ãæãããŸãã ããã䜿çšããã«ã¯ãæåã«ãšã³ãã£ãã£ããŒã¿ã¢ãã«ãäœæããå¿ èŠããããŸãã
ãã®åŸã EntityDataSourceã³ã³ããŒãã³ãããã©ãŒã ã«ãã©ãã°ãã ObjectContextã¿ã€ãã®ObjectContextTypeããããã£ããEntity Data ModelãæäŸããã³ã³ããã¹ãã®ããããã«èšå®ããŸã ã ïŒEF6ãããå Žåã¯ãObjectContextTypeã®ä»£ããã«DbContextTypeããããã£ã䜿çšããŸãïŒã ãããè¡ããšã EntityDataSourceã³ã³ããŒãã³ãã¯ã³ã³ããã¹ããªããžã§ã¯ããäœæãããªãã¬ã¯ã·ã§ã³ã䜿çšããŠãã³ã³ããã¹ãã§äœ¿çšå¯èœãªãã¹ãŠã®ããŒã¿ãœãŒã¹ãæ€çŽ¢ããŸãã ãããã®ããŒã¿ãœãŒã¹ã¯ã IListSourceå®è£ ã䜿çšããŠãã¶ã€ããŒã«è¡šç€ºãããŸãã
ãã®åŸãã³ã³ãããŒã«ããã©ãŒã ã«è¿œå ããéåžžã©ããDataSource ã DataMember ãããã³Bindingããããã£ã䜿çšããŠããããEntityDataSourceã«é¢é£ä»ããããšãã§ããŸãã 1ã€ã®EntityDataSourceã¯ãã¢ãã«å ã®ãã¹ãŠã®ããŒãã«ãšãã¥ãŒãžã®ã¢ã¯ã»ã¹ãæäŸãã SaveChangesã¡ãœãããåŒã³åºãããšã«ãã£ãŠã®ã¿å€æŽãä¿åããŸãã
äŸ
EntityDataSourceã®åäœãç解ããæè¯ã®æ¹æ³ã¯ãããã€ãã®äŸãæ€èšããããšã§ãã 次ã®ã»ã¯ã·ã§ã³ã§ã¯ãEntityDataSourceã䜿çšããŠ4ã€ã®å žåçãªããŒã¿ãã€ã³ãã£ã³ã°ã·ããªãªãå®è£ ããæ¹æ³ã«ã€ããŠèª¬æããŸãã ãã¹ãŠã®ã¹ã¯ãªããã¯ã NorthwindããŒã¿ããŒã¹ã«åºã¥ããåäžã®ãšã³ãã£ãã£ããŒã¿ã¢ãã«ã䜿çšããŸãã
ããã䜿çšããã«ã¯ãæåã«ãšã³ãã£ãã£ããŒã¿ã¢ãã«ãäœæããå¿ èŠããããŸãã
ãšã³ãã£ãã£ããŒã¿ã¢ãã«ã®äœæ
ãšã³ãã£ãã£ããŒã¿ã¢ãã«ãäœæããã«ã¯ã ãœãªã¥ãŒã·ã§ã³ãšã¯ã¹ãããŒã©ãŒãŠã£ã³ããŠã§ãããžã§ã¯ãããªãŒãå³ã¯ãªãã¯ãã[ è¿œå ]ãéžæããŸãã æ°ããã¢ã€ãã ...ã
ãæ°ããã¢ã€ãã ã®è¿œå ããã€ã¢ãã°ããã¯ã¹ã衚瀺ãããŸã ã ãADO.NET Entity Data Modelããéžæããã¢ãã«ã«ååãä»ããŠããã©ãŒã ã®äžéšã«ãããè¿œå ããã¿ã³ãã¯ãªãã¯ããŸãã
[ ãšã³ãã£ãã£ããŒã¿ã¢ãã«ãŠã£ã¶ãŒã ]ãã€ã¢ãã°ããã¯ã¹ã衚瀺ãããŸãããã®ãã€ã¢ãã°ããã¯ã¹ã§ãäœæããã¢ãã«ïŒæ¢åã®ããŒã¿ããŒã¹ããçæãããã¢ãã«ãŸãã¯ç©ºã®ã¢ãã«ïŒãéžæããå¿ èŠããããŸãã æåã®ãªãã·ã§ã³ãéžæãã ã次ãžããã¯ãªãã¯ããŸãã
次ã®ã¹ãããã¯ãããŒã¿ããŒã¹ãéžæããŠã¢ãã«ãäœæããããšã§ãã æ¢åã®æ¥ç¶ãéžæãããã ãæ°ããæ¥ç¶ããã¿ã³ã䜿çšããŠæ°ããæ¥ç¶ãäœæã§ããŸãã ãã®äŸã§ã¯ãNorthwind SQL ServerããŒã¿ããŒã¹ãžã®æ¥ç¶ãäœæããŸãã
ããŒã¿ããŒã¹ãã¡ã€ã«ã¯ãNorthWnd.mdfããšåŒã°ããäŸã®äžéšã§ãã ããŒã¿ããŒã¹ãéžæãããšããŠã£ã¶ãŒãã¯ã ãšã³ãã£ãã£ããŒã¿ã¢ãã«ã«å«ããããŒãã«ããã¥ãŒãããã³ã¹ãã¢ãããã·ãŒãžã£ãéžæããããæ±ããŸãã ãã®äŸã§ã¯ã次ã®å³ã«ç€ºãããã«ããã¹ãŠã®ããŒãã«ãéžæããã ãã§ãã
ãå®äºããã¿ã³ãã¯ãªãã¯ããŠãã¢ãã«ãäœæããŸãã ãããžã§ã¯ãã«2ã€ã®èŠçŽ ãè¿œå ãããŸããXMLã䜿çšããæŠå¿µã¢ãã«ãèšè¿°ãããã¡ã€ã«ãModel1.edmxããšãããŒã¿ãProductãªã©ã®ãšã³ãã£ãã£ã¯ã©ã¹ã«ã¢ã¯ã»ã¹ããããã«äœ¿çšãããObjectContextãå«ãçæã³ãŒããå«ãé¢é£ãããModel1.Designer.csã åŸæ¥å¡ãªã©
edmxãã¡ã€ã«ãããã«ã¯ãªãã¯ããŸãã ããŒã¿ããŒã¹ã¹ããŒããçªç¶å€æŽããå ŽåããŸãã¯ã¢ãã«ã«å«ããå¿ èŠã®ããããŒãã«ãšãã¥ãŒã®ãªã¹ããå€æŽãããå Žåã¯ã Entity Data Model DesignerãŠã£ã³ããŠã衚瀺ãããã¢ãã«ã衚瀺ãç·šéãããã³ãã€ã§ãåäœæã§ããŸãã Designer.csãã¡ã€ã«ã§èªåçã«çæããããã¹ãŠã®ã¯ã©ã¹ã¯ãéšåãšããŠå®£èšãããŸãã ããã«ãããããŒã¿ããŒã¹ããã¢ãã«ãåäœæããå Žåã«å€æŽãããªãå¥ã®ãã¡ã€ã«ã«ããžãã¹ããžãã¯ãè¿œå ããããšã§ãããããæ¡åŒµã§ããŸãã
ããã§ã以äžã«ç€ºãããã«ããŒã¿ã¢ãã«ã䜿çšã§ããŸãã
public Form1() { InitializeComponent(); using ( var ctx = new NORTHWNDEntities()) { dataGridView1.DataSource = ctx.Products.ToList(); } }
ãã®ã³ãŒãã¯ãã¢ãã«ã®ããŒã¿ãæäŸããObjectContextãªããžã§ã¯ããäœæãããã¹ãŠã®è£œåãå«ããªã¹ããäœæããŠããªã¹ããããŒãã«ã«è¡šç€ºããŸãã ctx.SaveChangesïŒïŒã¡ãœãããåŒã³åºãããšã«ããã補åãç·šéããå€æŽãããŒã¿ããŒã¹ã«ä¿åã§ããŸãã
ã³ãŒããå®è¡ãããšãããã€ãã®é倧ãªå¶éããããŸãïŒããŒã¿ã®äžŠã¹æ¿ãããã£ã«ã¿ãŒåŠçããªã¹ããžã®ã¢ã€ãã ã®è¿œå ãåé€ããããŠãã¡ãããããŒãã«ãšãã£ã¿ãŒïŒGridïŒã䜿çšããéçºäžã®ããŒãã«åïŒGridïŒã®æ§æã¯ã§ããŸããã
ãããã®å¶éã¯ããªã¹ãããœãŒã¹ãšããŠäœ¿çšããããšããäºå®ã«ãããã®ã§ãïŒåãªãããŒã¿ã®ãã¹ãããã·ã§ãããïŒã Winformsãèªåçã«äœæããIBindingList㯠ããã®å Žåãæå°éã®æ©èœã®ã¿ãæäŸããŸãã
ã°ãªãããã¥ãŒã®äœæïŒãªãŒãã«ãã¯ã¢ããã䜿çšïŒ
ãããã®æ¬ ç¹ã解æ¶ããã«ã¯ã EntityDataSourceã³ã³ããŒãã³ãããã©ãŒã ã«è¿œå ãã[ ããããã£]ãŠã£ã³ããŠã§ãäžã®å³ã«ç€ºãããã«ããã®ObjectContextTypeããããã£ããSample.NORTHWNDEntitiesãã«èšå®ããŸã ïŒæ³šïŒEF6ãããå Žåã¯ãObjectContextTypeã®ä»£ããã«DbContextTypeã䜿çšããŸãïŒã
EntityDataSourceã³ã³ããŒãã³ãã¯ã ObjectContextTypeã®å€ã䜿çšããŠãªããžã§ã¯ãã®ã³ã³ããã¹ããäœæããããŒã¿ã¢ãã«ã«èšè¿°ãããŠãããã¹ãŠã®èŠçŽ ã®ãã¥ãŒãçæããŸãã
次ã«ã DataGridViewã³ã³ãããŒã«ããã©ãŒã ã«è¿œå ãã[ ããããã£]ãŠã£ã³ããŠã§ã以äžã«ç€ºãããã«ã DataSourceããããã£ãentityDataSource1ã«ã DataMemberããããã£ãProductsã«èšå®ããŸãã
DataGridViewã«åãèªåçã«äœæããã Productã¯ã©ã¹ã®ããããã£ã衚瀺ãããŸã ã ãã¶ã€ããŒã¢ãŒãã§ã¯ãåã®é åºãå€æŽããå¹ ãã¿ã€ãã«ãé 眮ã圢åŒãªã©ãèšå®ã§ããŸãã
ããã§ãããžã§ã¯ããéå§ãããšãããŒãã«ãèªåçã«å ¥åãããèŠçŽ ã®ç·šéã䞊ã¹æ¿ããè¿œå ãåé€ãªã©ãå¿ èŠãªãã¹ãŠã®ã¢ã¯ã·ã§ã³ãå®è¡ã§ããããšãããããŸãã
EntityDataSourceã³ã³ããŒãã³ãã¯EntityBindingListã¯ã©ã¹ã®è£œåãªã¹ããã©ãããããããããã¯ãã¹ãŠå¯èœã§ãããã®ã¯ã©ã¹ã¯IBindingListViewã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ãã ã¢ã€ãã ã®äžŠã¹æ¿ãããã£ã«ã¿ãªã³ã°ãè¿œå ãåé€ããµããŒãããŸãã
å€æŽãä¿åãã
ããŒã¿ãç·šéããåŸãããããå€æŽãããŒã¿ããŒã¹ã«ä¿åããå¿ èŠããããŸãã ãããè¡ãæ¹æ³ã瀺ãã«ã¯ããã©ãŒã ã«3ã€ã®ãã¿ã³ãè¿œå ãã Textããããã£ããä¿åããããã£ã³ã»ã«ããããã³ãæŽæ°ãã«èšå®ãããããã®ãã¿ã³ã®Clickã€ãã³ãã«æ¬¡ã®ãã³ãã©ãŒãã¢ã¿ããããŸãã
// save/cancel/refresh changes in the data source void _btnSave_Click(object sender, EventArgs e) { entityDataSource1.SaveChanges(); } void _btnCancel_Click(object sender, EventArgs e) { entityDataSource1.CancelChanges(); } void _btnRefresh_Click(object sender, EventArgs e) { entityDataSource1.Refresh(); }
ãã®ã³ãŒãã¯äžç®çç¶ã§ãã æåã®ãã¿ã³ã¯ããã¹ãŠã®å€æŽãããŒã¿ããŒã¹ã«ä¿åããŸãã 2çªç®ã¯ããŒã¿ãåæœåºããŠå€æŽããã£ã³ã»ã«ãã3çªç®ã¯å€æŽãä¿åããŠããŒã¿ãå床éžæããŸãã
å¿ããããã¡ãªéèŠãªè©³çŽ°ã1ã€ãããŸããããŒã¿ããŒã¹ã«å€æŽãä¿åãããšãäŸå€ãçºçããå ŽåããããŸãã ããšãã°ãããŒã¿ããŒã¹ã®æŽåæ§å¶éã«éåããå€æŽãä¿åãããšãã æ®å¿µãªããããã®ã¿ã€ãã®äŸå€ã«å¯ŸåŠããããã®äžè¬çãªã¬ã·ãã¯ãããŸããã ãããã®æ§è³ªã¯ãããŒã¿ããŒã¹ã¹ããŒããšã¢ããªã±ãŒã·ã§ã³èªäœã«äŸåããŸãã
èããããäŸå€ãã©ã®ããã«åŠçãããã«é¢ä¿ãªããæåã«ãã¹ãããšã¯ãããããã£ããããããšã§ãã ãããè¡ãã«ã¯ã SaveChangesã¡ãœããã®åŒã³åºããtry / catchãããã¯ã§ã©ãããããã DataErrorã€ãã³ããã³ãã©ãŒãEntityDataSourceã³ã³ããŒãã³ãã«è¿œå ããŸãã ããã¯ãã¢ããªã±ãŒã·ã§ã³ãããŒã¿ãä¿åãããšãã«èµ·ãããããšã©ãŒãåŠçããæ¹æ³ã§ãã
// report any errors void entityDataSource1_DataError(object sender, DataErrorEventArgs e) { MessageBox.Show("Error Detected:\r\n" + e.Exception.Message); entityDataSource1.CancelChanges(); e.Handled = true; }
ã³ãŒãã¯èŠåãçºè¡ããå€æŽãç Žæ£ããHandledãã©ã¡ãŒã¿ãŒãTrueã«èšå®ããŠããšã©ãŒãæ¢ã«åŠçãããŠãããäŸå€ãã¹ããŒããå¿ èŠããªãããšã瀺ããŸãã
èŸæžæ€çŽ¢ã䜿çšããŠé¢é£ãšã³ãã£ãã£ãè¡šã
ãã®äŸãçµäºããããã«ãéåžžã®ã·ããªãªãèŠãŠã¿ãŸãããã Productã¯ã©ã¹ã«ã¯ãCategoryãšSupplierãšãã2ã€ã®ããããã£ãããããããã¯é¢é£ãããšã³ãã£ãã£ã§ãã ããã©ã«ãã§ã¯ããããã®ããããã£ã¯ããŒãã«ã«è¡šç€ºãããŸããããåãšãã£ã¿ãŒã䜿çšããŠããããã®ãšã³ãã£ãã£ã®åãããŒãã«ã«è¿œå ã§ããŸãã 以äžã®ç»åã¯ããããè¡ãæ¹æ³ã瀺ããŠããŸãã
åé¡ã¯ãDataGridViewãé¢é£ãããšã³ãã£ãã£ã®è¡šç€ºæ¹æ³ãç¥ããªããããããã©ã«ãã§ToStringã¡ãœããã䜿çšãããã ãã§ããã®çµæãã»ã«ã«ãSample.Categoryãããã³ãSample.Supplierããšããå€ãå ¥åããã2ã€ã®èªã¿åãå°çšåãåŸãããããšã§ãã ã
ããããå®éã®ä»äºãããã«ã¯ãä»å ¥å ã®ã«ããŽãªãšååã衚瀺ããåãå¿ èŠã§ããçæ³çã«ã¯ããªã¹ãããéžæããŠã«ããŽãªãšä»å ¥å ãå€æŽã§ãããšãã£ã¿ãå¿ èŠã§ãã ããã¯éåžžãã«ã¹ã¿ã åïŒ DataGridViewã³ã³ãããŒã«ã䜿çšããå Žåã¯DataGridViewComboBoxColumnå ïŒãäœæããŠãã€ã³ãããã³ãŒããèšè¿°ããããšã«ãã£ãŠè¡ãããŸã ã
ãªããªã ããã¯äžè¬çãªã·ããªãªã§ããã EntityDataSourceã³ã³ããŒãã³ãã¯æ¡åŒµAutoLookupããããã£ããµããŒãããŸãã ãã®ããããã£ã¯ããã©ãŒã ã«é 眮ãããDataGridViewãŸãã¯C1FlexGridã³ã³ãããŒã«ã§èªåçã«äœ¿çšå¯èœã«ãªããŸãïŒ C1FlexGridã§ã¯ ã DataGridViewãããã¯ããã«é«éã§æŽç·Žããã衚圢åŒã®ããŒã¿è¡šç€ºçšã®äžè¬çãªã³ã³ããŒãã³ãã§ãïŒã
EntityDataSourceã³ã³ããŒãã³ãã¯C1FlexGridããµããŒãããŠããŸãããEFWinFormsã¢ã»ã³ããªã¯C1FlexGridã¢ã»ã³ããªããç¬ç«ããŠããããšã«æ³šæããŠãã ããã ããã¯ãå®è¡æã«ããããã£ããã€ã³ãããããã«äž»ã«ãªãã¬ã¯ã·ã§ã³ã«äŸåããdynamicããŒã¯ãŒãã䜿çšããããšã§å®çŸãããŸãã
以äžã®å³ã¯ã DataGridView㧠AutoLookupããããã£ãæå¹ã«ããæ¹æ³ã瀺ããŠããŸã ã
AutoLookupããããã£ãæå¹ã«ãããšã EntityDataSourceã³ã³ããŒãã³ãã¯ããŒãã«å ã®åãèªåçã«ã¹ãã£ã³ãããšã³ãã£ãã£ã«ãã€ã³ããããåããé¢é£ãããšã³ãã£ãã£ã®å¯èœãªå€ã®ãªã¹ããå«ããããŒã¿ããããã«åºã¥ããŠç·šéå¯èœãªåã«çœ®ãæããããããã®å€ã衚瀺ããŸãã
次ã®å³ã¯ã AutoLookupããããã£ãTrueã«èšå®ããçµæã瀺ããŠããŸãã
[ã«ããŽãª]åãš[ãµãã©ã€ã€]åã«ã«ããŽãªåãšãµãã©ã€ã€åãã©ã®ããã«è¡šç€ºããããããªã¹ãããæ°ãããµãã©ã€ã€ãéžæããã ãã§è£œåã®ãµãã©ã€ã€ãå€æŽã§ããããšã«æ³šæããŠãã ããã
EntityDataSourceãããŒãã«ã«è¡šç€ºããé¢é£ãšã³ãã£ãã£ããç®çã®ãã£ãŒã«ããã©ã®ããã«éžæããã®ãçåã«æããããããŸããã ããã¯ã次ã®ã¢ã«ãŽãªãºã ã䜿çšããŠè¡ãããŸãã
- ã¯ã©ã¹ãïŒåã«ç¶æ¿ããã ãã§ãªãïŒ ToStringã¡ãœãããå®è£
ããå Žåã ToStringå®è£
ã䜿çšããŠãšã³ãã£ãã£ãè¡šããŸãã
- ããã§ã¯ãªããã¯ã©ã¹ã«stringåã®ããããã£ãããããã®ååã«ãNameããšããåèªãããå Žåããã®ããããã£ã¯ãšã³ãã£ãã£ãè¡šãããã«äœ¿çšãããŸãã
- ããã§ã¯ãªããã¯ã©ã¹ã«stringåã®ããããã£ãããããã®ååã«ãDescriptionããšããåèªãããå Žåããã®ããããã£ã¯ãšã³ãã£ãã£ãè¡šãããã«äœ¿çšãããŸãã
- äžèšã®ããããåœãŠã¯ãŸããªãå Žåããã®ã¯ã©ã¹ã«å¯ŸããŠããŒã¿ãã€ã³ãã£ã³ã°ãå®è¡ã§ããŸããã
æåã®ã«ãŒã«ã¯æãäžè¬çã§æè»ã§ãã ããšãã°ãNorthwindããŒã¿ããŒã¹ã®Employeeã¯ã©ã¹ã«ã¯Firstnameããããã£ãšLastnameããããã£ããããŸã ã ãããã®1ã€ã¯ãªã¹ãå ã®ãšã³ãã£ãã£ãè¡šãããã«äœ¿çšã§ããŸãããçæ³çã«ã¯äž¡æ¹ã䜿çšããããšæããŸãã ãããè¡ãã«ã¯ã Employeeã¯ã©ã¹ã®ToStringã¡ãœããããªãŒããŒã©ã€ãããäž¡æ¹ã®ããããã£ã§æ§æãããè¡ãäœæããŸãã
/// <summary> /// Add a field with the employee's full name /// </summary> public partial class Employee { public string FullName { get { return string.Format("{0} {1}", FirstName, LastName); } } public override string ToString() { return FullName; } }
éšåã¯ã©ã¹ã䜿çšãããšãADO.NET Entity FrameworkãŠã£ã¶ãŒãã䜿çšããŠäœæãããæšæºã¯ã©ã¹ãæ¡åŒµãããããšã«æ³šæããŠãã ããã ããæç¹ã§ããŒã¿ãšã³ãã£ãã£ã¢ãã«ãåçæããå Žåã ToStringã¡ãœããã®å®è£ ã¯åœ±é¿ãåããŸããã
NorthwindããŒã¿ããŒã¹ã§ã¯ãããŒã¿ããã€ã³ãããããã«ç¹å¥ãªã¡ãœãããå¿ èŠãšããã¯ã©ã¹ã¯Employeeã®ã¿ã§ãã ä»ã®ãã¹ãŠã®ã¯ã©ã¹ã«ã¯ã ãCustomerNameãããCategoryDeââscriptionããªã©ã®ããããã£ãããããããã¯EntityDataSourceã³ã³ããŒãã³ãã«ãã£ãŠèªåçã«äœ¿çšãããç®çã®å¹æãæäŸããŸãã
æåã®äŸã¯çµãããŸããã