ç§ã«ãšã£ãŠã®VS 2010ã®åºåã¯ããŸã第äžã«ã.Net 4ãEntity Framework 4ãASP.NET MVC 2ã§åäœããèœåã§ãã
ç§ã®æèŠã§ã¯ãåŸããããã¹ãŠã®çè«çç¥èã¯å®éã®çµéšã§è¡šçŸãããã¹ãã§ãã ãã®ãããæ©äŒãäžãããããããã«ãVS 2010ã䜿çšããŠãããžã§ã¯ããå®è£
ããŸãããããã§ãæ°ããæ©èœã®å°è±¡ãå
±æããæºåãæŽããŸããã
ãã®èšäºã¯ãé«åºŠãªéçºè
åãã«èšèšãããŠããŸãïŒ
å°ãåã®ã€ã³ã¿ãã¥ãŒã®1ã€ã§ãVS 2010ã䜿çšããŠè¡ãããšã«ããã¿ã¹ã¯ãæäŸãããŸããã æ¡ä»¶ã§ã¯ããã§ãªããã°åæãããŸããã§ããã ç§ã«ãšã£ãŠãã®ä»äºã¯ããŸã第äžã«ãæäŸãããæ©äŒã«æ
£ããè¯ãæ©äŒã§ããã
æ¡ä»¶ã«ã€ããŠç°¡åã«èª¬æã
ãŸããMSSQL Server NorthWindããŒã¿ããŒã¹ã® CustomersããŒãã«ã®ããŒã¿ãæ€çŽ¢ããã³è¡šç€ºããããã®Webã¢ããªã±ãŒã·ã§ã³ãäœæããŸã ã æ€çŽ¢ã¯ãåœïŒåœïŒãåžïŒåžïŒãäŒç€ŸåïŒäŒç€ŸåïŒã®åºæºã«åŸã£ãŠå®è¡ããå¿
èŠããããŸãã æ€çŽ¢èªã¯éšåçã«æå®ã§ããããšã«æ³šæããŠãã ãããäœãããããŠãŒã¶ãŒãã¬ã³ããªãŒãªãœãªã¥ãŒã·ã§ã³ãäœæããã®ã奜ãã§ãã ç§ã®æèŠã§ã¯ãWebäžã®ãŠãŒã¶ãŒã«ãšã£ãŠæé©ãªãœãªã¥ãŒã·ã§ã³ã¯ajaxã§ãã ã€ãŸããããŒãžããªããŒãããããšãªãããµã€ãã®ä»äºã äœæããç®æšãšããŠèšå®ããã®ã¯ããã®ã€ã³ã¿ãŒãã§ã€ã¹ã§ãã
éšåã®éžæ
ç§ã¯ãåžžã«ä»äºãããŠããããŒã«ããèªåãäžçªå¥œããªãã®ãéžã¶ããšã«ããŸããã
1ã€ç®ã¯
jQueryã§ãã å€ãã®å Žåããªãããªã€ã³ã¿ãŒãã§ã€ã¹ãéçºããå¿
èŠãããããã®ãã¬ãŒã ã¯ãŒã¯ã倧奜ãã ããã§ãã 圌ãVSã«å
¥ãåã®é·ãéããããŠåœŒã®å€§è¡åã 圌ã®æè»æ§ã®ãããã§ãããªãã¯ãžã§ãã€ã®ããã«æããŸãïŒ
第äºã«ãããã¯Entity Framework 4ã§ããç§ã¯ãããŒãžã§ã³3.5ããããã»ã©åã§ã¯ãªãããšã«æ
£ããŠããŸãã MSã¯éçºè
åãã«EFãæšå¥šããŠããŸããEFéçºè
ã®ããã°ãèªããšãEF 4ãæåŸ
ãããŠãããã®ã§ãããšç¢ºä¿¡ããŸããã æåŸã«ãã¢ããã¿ãŒãæ¥ä»ãªããžã§ã¯ãããåé¢ããçµã¿èŸŒã¿æ©èœããããŸãã ããã«ã€ããŠã¯åŸã§èª¬æããŸã
ãPocoã¯t4ãã³ãã¬ãŒãã«åºã¥ããŠãªããžã§ã¯ããçæããããšãæå³ããŸãã ãããŠãLinq to Entityã®ååšã¯ããã®ãã¬ãŒã ã¯ãŒã¯ã«åã軜ãã®æèŠãè¿œå ããŸãã
ç§ã«ã©ã€ãã»ãŒããŒïŒ ïŒ
第äžã«ãASP.NET MVC 2ã¯ã¢ããªã±ãŒã·ã§ã³ã®åºç€ã§ãã 圌女ãããã«ããªãã£ããšããç§ã¯å³èã®ããŒã«ïŒæžãæããã¹ãã¯ã©ã€ã¢ã³ããã¥ãŒãWebãµãŒãã¹åœ¢åŒã®ã³ã³ãããŒã©ãŒãªã©ïŒã®å©ããåããŠéåžžã«äŒŒããããªããšãè¡ããMSããã®è§£æ±ºçãåºãŠãããšãã«åã³ãæšãŠãŸããã ãªãªãŒã¹ä»¥æ¥ãmvcã䜿çšã§ããã®ã¯å¹žéã§ããã ããããŸãç§ã®æã§ãïŒ
æåŸã«ãajaxã«ã€ããŠã¯ãWebãµãŒãã¹ã䜿çšããããšã«ããŸããã å®éã®ãšãããç§ã¯ãŠã§ããã·ã¹ãã ã®äžéšã«ãããªãç°çš®ã¢ããªã±ãŒã·ã§ã³ã®éçºã«å¿ããããŸã ä»ã®ãœãããŠã§ã¢ããããããããŸãã ã¯ããWCFãã»ã®ããããŠããŸãïŒ WebãµãŒãã¹ã¯DTOã亀æããããããããã«ããŒã¿å±æ§ãè¿œå ããããããããµãŒãã¹ã³ã³ãã©ã¯ããäœæã§ããŸããä»ã®ãŠãŒã¶ãŒã¯ã¢ããªã±ãŒã·ã§ã³ã䜿çšã§ããŸãã
ãŸããããããã§ããïŒ ïŒ
ãžã°ãœãŒããºã«
ã¢ãŒããã¯ãã£ã«é¢ããŠã¯ãäžè¬ã«åãå
¥ããããŠããæšæºãé å®ããŠããŸãã ãã®ç¹ã«é¢ããŠMSãæ確ã«ãã®èŠè§£ãè¡šæããããšãéåžžã«å¬ããæããŸãã ç§ãã¡ã®ãããžã§ã¯ãã§èŠããŠããã¹ãããšïŒ
- ã€ãªããã®å°ãªãåå
- åå±€ã¯åã®ãã®ã«ã€ããŠã®ã¿ç¥ã£ãŠãã
ã¬ã€ã€ãŒãšã¯
- ãã¥ãŒïŒxHtml + jsïŒ
- ïŒWebïŒã¢ããªã±ãŒã·ã§ã³ïŒasp.net vewãWebãµãŒãã¹ïŒ
- ããŒã¿ã¢ã¯ã»ã¹å±€ïŒEntity FrameworkïŒ
- ããŒã¿ããŒã¹ïŒSQL ServerïŒ
ããŒã¿è»¢éãªããžã§ã¯ãïŒDTOïŒã䜿çšããŠäºãã«éä¿¡ããŸã
ç¿æ
£ããããŸã-åžžã«è¡šç€ºããå§ããŸãïŒ
ãã¥ãŒãäœæãã
Index.aspxãå€æŽããŸãã
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
< form id ="customer-search-form" action ="/" enctype ="application/x-www-form-urlencoded" method ="get" > < label > Company Name < input name ="name" /></ label > < label > City < input name ="city" /></ label > < label > Country < input name ="country" /></ label > < input type ="submit" value ="search" /> </ form > < div id ="customer-search-result" > < table > < thead > < tr > < th class ="CustomerID" > id </ th > < th class ="CompanyName" > name </ th > < th class ="ContactTitle" > contract </ th > < th class ="City" > city </ th > < th class ="Country" > country </ th > < th class ="Phone" > phone </ th > < th class ="Fax" > fax </ th > </ tr > </ thead > < tbody ></ tbody > </ table > </ div > * This source code was highlighted with Source Code Highlighter .
ããã§ã¯ãããããã¹ãŠãæããã§ãã thã§ã¯ã¯ã©ã¹ã®ååã®ã¿ã説æããŸãã ãããã¯ãéžæã衚瀺ããããã®ã¿ã°ãšããŠäœ¿çšãããŸãã ãããžã§ã¯ãã§ã¯ãjQueryã«ããã€ãã®ãã©ã°ã€ã³ãè¿œå ããããšã«ããŸããã
- DataTable㯠ãã°ãªãããpage'natorã䞊ã¹æ¿ãã衚瀺ããããã«å¿
èŠã§ãã
- ãã©ãŒã ã®æ€çŽ¢ãªãã·ã§ã³ã䟿å©ã«éžæããããã®ãªãŒãã³ã³ããªãŒã ã
- èŠæ±ãWebãµãŒãã¹ã«æ£ããéä¿¡ããããã®Json ã
Site.Masterã®æ¥ç¶æžã¿ãã©ã°ã€ã³ãžã®ãªã³ã¯ãè¿œå ããjsãã¡ã€ã«ãè¿œå ããŸãããããcustomer-list.jsãšåŒã³ãŸã
Javascript
ç§ã¯
ã¯ããŒãžã£ãŒãäœã§ããããç¥ã£ãŠããã®ã§ãæåãšæåŸã«è¿œå ããŠãã ããïŒ
( function (){
$( function (){
//.... ...
});
})();
* This source code was highlighted with Source Code Highlighter .
åæã«ããŠã³ããŒãã³ãŒãã®éå§ãè¿œå ããŸãã ãªããªã 1ã€ã®ãã¥ãŒããããjQueryãã©ã°ã€ã³ãå®è¡ããŸããã§ãã
WebãµãŒãã¹ã«æ¥ç¶ããããã«Ajaxãæ§æããŸãã
$.ajaxSetup({
type: 'post' ,
contentType: 'application/json; charset=utf-8' ,
dataType: "json"
});
* This source code was highlighted with Source Code Highlighter .
䜿çšãããã®ãèŠã€ããŸãã
var $result = $( '#customer-search-result' );
var $form = $( '#customer-search-form' );
* This source code was highlighted with Source Code Highlighter .
質åã¯ããããããå€æ°ã®å
é ã«$ãåŒãèµ·ãããŸãïŒPHPã¯ãããšã¯äœã®é¢ä¿ããããŸããïŒjQueryã§ã©ãããããå€æ°ãåŒã³åºããŠãããã«èŠããããã«ããŸãã ãããŠã圌ãã«äœãæåŸ
ãããã¯æããã§ãã
次ã«ã
ãªãŒãã³ã³ããªãŒããæ§æããŸãã ãªããªã 3ã€ã®ãã£ãŒã«ããš3ã€ã®å¯Ÿå¿ãããµãŒãã¹ããããŸããèšå®ã1ã€ã®ãªããžã§ã¯ãã«çµåããŠããã次ã䜿çšããæ¹ãç°¡åã§ãã
var paramsAutocomplete = {
name: '' ,
queryParams: function (info){
var res = {};
res[ this .name] = info.q;
return $.toJSON(res);
},
formatItem: function (row, i, max, term) {
return row.replace( new RegExp( "(" + term + ")" , "gi" ), '$1' );
},
parse: function (data) {
var parsed = [];
$.each(data.d, function (){
parsed.push({data: this , value: this , result: this });
});
return parsed;
}
};
* This source code was highlighted with Source Code Highlighter .
æšæºã®é
ä¿¡ã§ã¯
queryParamsé¢æ°ã«æ³šæãã䟡å€ã
ãããŸããã
ãªãŒãã³ã³ããªãŒãã§ã¯ãã®ãããªãã©ã¡ãŒã¿ãŒã®å€æŽã¯èš±å¯ãããŠããŸããã ãã®ã³ãŒããæ©èœããããã«ããã®ãã©ã°ã€ã³ããããã«å€æŽããŸããããã¡ãããããã©ã«ãã§æ©èœãããªãã·ã§ã³ãæ®ããŸããã
data: options.queryParams ? options.queryParams({
q: lastWord(term),
limit: options.max
}) : $.extend({
q: lastWord(term),
limit: options.max
}, extraParams),
* This source code was highlighted with Source Code Highlighter .
Ajaxãªã¯ãšã¹ããçºçãã348è¡ã®ããã«èŠããŸãã ããã¯ãWebãµãŒãã¹ãšã®äºææ§ã®ããã«è¡ãããŸãã
ãªãŒãã³ã³ããªãŒããæ¥ç¶ããŸãïŒ
var $name = $form.find( '[name=name]' )
.autocomplete(
'Services/Customers.asmx/CompanyNames' ,
$.extend(paramsAutocomplete, {name: 'name' }));
var $city = $form.find( '[name=city]' )
.autocomplete(
'Services/Customers.asmx/Cities' ,
$.extend(paramsAutocomplete, {name: 'city' }));
var $country = $form.find( '[name=country]' )
.autocomplete(
'Services/Customers.asmx/Countries' ,
$.extend(paramsAutocomplete, {name: 'country' }));
* This source code was highlighted with Source Code Highlighter .
衚瀺ãããã£ãŒã«ããåéããŸãã
var $table = $result.find( 'table' );
var labels = ( function (){
var res = [];
$table.find( 'thead th' ).each( function ()
{
res.push($( this ).attr( 'class' ));
});
return res;
})();
* This source code was highlighted with Source Code Highlighter .
次ã«ãããŒã¿ãœãŒã¹ã§ããWebãµãŒãã¹ãšé£æºããããã«
DataTableãæ§æããå¿
èŠããããŸãã
var lastLength = 10;
var dataTable = $table.dataTable({
bProcessing: true ,
bServerSide: true ,
sPaginationType: 'full_numbers' ,
sAjaxSource: 'Services/Customers.asmx/Search' ,
fnServerData: function ( sSource, aoData, fnCallback ) {
// aoData
var findByLabel = function (o, name)
{
var res = null , find = false ;
$(o).each( function (){
if (!find && this .name === name)
{
find = true ;
res = this .value;
}
});
return res;
};
// dataTable'
var convert = function (list)
{
var res = [];
$(list).each( function (){
var item = [];
var row = this ;
$(labels).each( function ()
{
item.push(row[ this ]);
});
res.push(item);
});
return res;
};
var onPage = aoData ? findByLabel(aoData, 'iDisplayLength' ) : lastLength;
var start = aoData ? findByLabel(aoData, 'iDisplayStart' ) : 0;
var sortField = aoData ? findByLabel(aoData, 'iSortCol_0' ) : 0;
var sortIsAsc = aoData ? findByLabel(aoData, 'sSortDir_0' ) === 'asc' : true ;
lastLength = onPage;
//
//
$.ajax( {
url: sSource,
data: $.toJSON({
name: $name.val(),
city: $city.val(),
country: $country.val(),
order: {
Field: labels[sortField],
Dir: sortIsAsc ? 'Ascending' : 'Descending'
},
start: start,
onPage: onPage
}),
success: function (data){
fnCallback({
iTotalRecords: data.d.Count,
iTotalDisplayRecords: data.d.Count,
aaData: convert(data.d.List)
});
}
} );
}
});
* This source code was highlighted with Source Code Highlighter .
ç§ã®æå¿ã§ããã°ããã®
DataTableããŸã£ããå¥ã®æ¹æ³
ã§èšè¿°ããŠã
ãŸãã ã 圌ã¯åœŒãšäžç·ã«åãããã«ããŸãã«ãå€ãã®åããå¿
èŠãšããããã¯éãã§ãã ç§ã¯ãã®ã³ãŒããäžçªå¥œãã§ã¯ãªãããšãŠãããã°ã£ãŠããŸãã
DataTableã䜿çšãããšãå
éšã¡ã«ããºã ã䜿çšããŠåãæ©èœãå®è£
ã§ããŸãããã³ãŒãã®å¿«é©æ§ã¯ããã«äœäžãããšæããŸãã
éä¿¡åŠçããã©ãŒã ã«è¿œå ããŸã
$form.submit( function (){
dataTable.fnDraw( true );
return false ;
});
* This source code was highlighted with Source Code Highlighter .
JSã§å®äºã§ãã VSã§æåã«æ³šç®ã§ããããšã¯ãJSã³ãŒãã§äœæ¥ããããšã䟿å©ã«ãªã£ãããšã§ãã ç解ã§ããªãã€ã³ãã³ãã«ãããžã£ã³ããã³ãŒãæ€èšŒã«ãããã¬ãŒãã¯ãããããŸããã jQueryãã³ãã®ååšãšè¿œå ããã
Lint JSã«ãããVSã¯æé«ã®JavaScriptã³ãŒããšãã£ã¿ãŒã®1ã€ã«ãªããŸãã
WebãµãŒãã¹
WebãµãŒãã¹Customers.asmxãäœæãã[ScriptService]ã®ã³ã¡ã³ããå€ããSystem.Web.Script.Servicesã䜿çšããŠè¿œå ããŸãã
ã¡ãœãããäœæããŸãã
- æåå[] CompanyNamesïŒæåååïŒ
- æåå[]éœåžïŒæååéœåžïŒ
- æåå[]åœïŒæååã®åœïŒ
- çµæ<VS2010.Customers>æ€çŽ¢ïŒæåååãæååéœåžãæåååœããœãŒãé ãint startãint onPageïŒ
å¿
èŠãªå±æ§ãè¿œå ããŸãã
[WebMethod]
[ScriptMethodïŒResponseFormat = ResponseFormat.JsonïŒ]
JSON圢åŒã§ã®äœæ¥ã«å¿
èŠã§ããããã¹ãããŒã¿ããŠã§ãã«è»¢éããã®ã«é©ããŠããŸããå€ãã®çç±ããããŸããããç°¡æœãèªã¿ãããã解æãé«éã§ãã
æåã®3ã€ã®ã¡ãœããã¯åãæ¹æ³ã§å
¥åãããŸããããã®ãã¡ã®1ã€ã ãã®äŸã瀺ããŸãã
using ( var context = new NorthwindEntities())
{
return context.Customers
.Where(c => c.CompanyName.Contains(name))
.Select(c => c.CompanyName)
.Distinct()
.OrderBy(n => n)
.ToArray();
}
* This source code was highlighted with Source Code Highlighter .
ã³ã³ããã¹ããéããèŠã€ããŠãç§ãã¡ã«æåŸ
ãããããšãè¿ããŸãã Linq to Entitiesã¯ãããselectã«å€æããToArrayãåŒã³åºãããšãã«ã®ã¿å®äœåããŸãã ãšããã§ããªãToArrayãç¹å¥ã«äœ¿çšããŠããã®ã§ããã ãã®çç±ã¯ããã®ãµãŒãã¹ãWCFã§åäœãããã®ãç°¡åã«ãªãããã§ãã ãªããªã é
åã¯ã³ã³ãã©ã¯ãã§èšè¿°ã§ããŸãã
ããé£ããæ€çŽ¢ïŒ
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Result<VS2010Lab.Customers> Search( string name, string city, string country, Sort order, int start, int onPage)
{
//
if (order == null || ! typeof (VS2010Lab.Customers).GetProperties().Any(f => f.Name == order.Field))
order = new Sort {Field = "CompanyName" , Dir = SortDirection.Ascending};
using ( var context = new NorthwindEntities())
{
//
var res = context.Customers
.Where(c => string .IsNullOrEmpty(name) || c.CompanyName.Contains(name))
.Where(c => string .IsNullOrEmpty(city) || c.City == city)
.Where(c => string .IsNullOrEmpty(country) || c.Country == country)
//
.Order(order);
// , DTO
return new Result<VS2010Lab.Customers>
{
// pagenator'
Count = res.Count(),
List = res.Paginate(
new ListFilter
{
Start = start,
Count = onPage
}
).ToArray()
};
}
}
* This source code was highlighted with Source Code Highlighter .
泚æãã¹ãããšïŒæ³šæãããŒãžããŒã·ã§ã³ã IQueryableã®æ¡åŒµæ©èœãšããŠèª¬æããŸããã
public static IQueryable Order( this IQueryable query, Sort sort)
{
return sort.Dir == SortDirection.Ascending ?
query.Order(sort.Field) :
query.OrderDescending(sort.Field);
}
public static IQueryable Order( this IQueryable query, string name)
{
return query.ApplyOrder(name, "OrderBy" );
}
public static IQueryable OrderDescending( this IQueryable query, string name)
{
return query.ApplyOrder(name, "OrderByDescending" );
}
public static IQueryable Paginate( this IQueryable query, IListFilter filter)
{
return filter.Count > 0 ? query.Skip(filter.Start).Take(filter.Count) : query;
}
* This source code was highlighted with Source Code Highlighter .
Entity Framework 4
ADO.NET Entity Data Model ïŒedmxïŒãäœæããããã«Customersãã¬ãŒããè¿œå ããŸãã
ã¢ãã«ã®ç»é¢ã®çœãé åã§ããŠã¹ã®å³ãã¿ã³ã§ãçªãããšã
ã³ãŒãçæé
ç®ã®è¿œå ããéžæããŸã

ããã§ã¯ãVS 2010ã®å¥ã®æ©èœã§ãããªã³ã©ã€ã³ãã³ãã¬ãŒããããŠã³ããŒãããŸãã éããŠã
ADO.NET CïŒPOCO Entity GeneratorãéžæããNorthwind.ttãªã©ã®ååãå
¥åããŠã[
è¿œå ]
ãã¯ãªãã¯ããŸãïŒ

ã¢ãã«ããããã£ïŒF4ïŒã«ç§»åãã次ãéžæããŸãã
- ã³ãŒãçææŠç¥ ãªã
- DDLçæãã³ãã¬ãŒã Northwind.tt
ããã§ãäžé£ã®ããŒã¿ãªããžã§ã¯ãïŒDOïŒãšããããæäœããã³ã³ããã¹ããã§ããŸããã EF3.5ã®ããã«ã圌ãã¯äžç·ã«åãã€ããŸããïŒ
åºæ¥äžããïŒ ïŒçµè«
èšäºã倧éã«ãããŸããããVS2010ã ãã§ãªãããã®ãããžã§ã¯ãã¯ãŸã£ããç°ãªããŸãããVS2010ã ãã§ãªããå€ãã®æžå¿µãåãäžããŸããã§ããã
ç§ã¯ãŸã åŠçã§ããããVSã®ããŒãžã§ã³5ã§äœæ¥ãéå§ããŸããã ãã以æ¥ãã¹ã¿ãžãªã¯å€§ããå€ãããŸããïŒãããŠãããã°ã©ããŒã®å質ãšäœ¿ãããããæ¹åããããã®æ³šæãé©åãªã¬ãã«ã«ãšã©ãŸã£ãŠããããšãå¬ããæããŸãã ãŸããMSãæçµçã«Webéçºè
ã«çŽé¢ããããšãé¡ã£ãŠããŸãã
IE5ã¯
HTML5ã®ãµããŒãã宣èšããŸããããããã¯ãŸã£ããå¥ã®è©±ã§ãïŒã
ã¬ãã¥ãŒããæå³çã«éãããã®ã¯ãããããªããšãæ··ä¹±ãããªãããã«
ããããžã§ã¯ãèªäœã§èŠãããšãã§ããŸãã
psïŒèšäºãæ°ã«å
¥ã£ãããæ祚ããŠãã ããã
ã³ã³ãã¹ãã«
åå ããŸã ïŒ