{"id":176017,"date":"2013-04-09T22:56:05","date_gmt":"2013-04-09T18:56:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=176017"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=176017","title":{"rendered":"<span class=\"post_title\">ASP NET.MVC \u0423\u0440\u043e\u043a 3. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0414<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430<\/b>: \u0418\u0437\u0443\u0447\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446, \u0441\u0432\u044f\u0437\u0435\u0439 \u0432 VS 2012). \u041a\u043e\u043c\u0430\u043d\u0434\u044b INSERT, UPDATE, DELETE, SELECT. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 LinqToSql \u0438 Linq. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u044f, IRepository, SqlRepository.<\/p>\n<h5>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0411\u0414<\/h5>\n<p>  \u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u2013 \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0441\u0432\u044f\u0437\u0438) \u043e\u0442 \u0430\u043d\u0433\u043b. relation.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h6>\u0422\u0430\u0431\u043b\u0438\u0446\u044b<\/h6>\n<p>   \u042d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/c96\/f33\/38e\/c96f3338e7b4428a4b0e275a905d1d81.gif\"\/><\/p>\n<p>  \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a. \u0421\u0442\u043e\u043b\u0431\u0446\u044b \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u2013 \u0438\u043c\u044f, \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445. <br \/>  \u0422\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438:  <\/p>\n<ul>\n<li>\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0435\u0441\u0442\u044c \u0438\u043c\u044f (\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435)<\/li>\n<li>\u043d\u0435\u0442 \u0434\u0432\u0443\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a<\/li>\n<li>\u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f (\u043d\u0435\u0442 \u0434\u0432\u0443\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432)<\/li>\n<li>\u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 (\u0442.\u0435. \u043d\u0435 \u043d\u0430\u0434\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u0442\u0440\u043e\u043a, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430)<\/li>\n<\/ul>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435:  <\/p>\n<ul>\n<li>\u0418\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/li>\n<li>\u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/li>\n<\/ul>\n<h6>\u0421\u0432\u044f\u0437\u0438<\/h6>\n<p>  \u041c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0432\u044f\u0437\u0438 (relation). \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0432\u044f\u0437\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u2013 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432) \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f ID. \u041e\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0438\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u043c, \u0442.\u0435. \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438, \u0442\u0430\u043c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f 1, 2, 3, 4\u2026 n+1, \u0433\u0434\u0435 n \u2013 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e ID.<\/li>\n<li>\u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u2013 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432) \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u044d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435, \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0435 [\u0418\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b]ID. \u041d\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u043c.<\/li>\n<li>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043a\u043b\u044e\u0447\u043e\u043c.<\/li>\n<\/ul>\n<p>  \u0421\u0432\u044f\u0437\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0442\u0440\u0435\u0445 \u0442\u0438\u043f\u043e\u0432:  <\/p>\n<ul>\n<li><b>\u041e\u0434\u0438\u043d-\u043a-\u043e\u0434\u043d\u043e\u043c\u0443.<\/b> \u0422.\u0435. \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u042d\u0442\u043e \u0440\u0435\u0434\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435, \u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u2014 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li><b>\u041e\u0434\u0438\u043d-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c.<\/b> \u041e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 A \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 B. \u041d\u043e \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 B \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 A. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 B \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 A.<\/li>\n<li><b>\u041c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c.<\/b> \u041e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0410 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0412, \u0447\u0442\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e \u0438 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e \u0441\u0432\u043e\u0438\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c, \u0438 \u0434\u0432\u0443\u043c\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 A \u0438 B.<\/li>\n<\/ul>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<h5>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0432 \u0411\u0414 <\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0411\u0414 \u0432 VS 2012:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/149\/efd\/c26\/149efdc2641aeda850e3f375869804fd.jpg\"\/><\/p>\n<p>  \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0451 LessonProject, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c 3 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Role User \u0438 UserRole.<br \/>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Role:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/455\/6f5\/f72\/4556f5f72ce57b28359c29e10ee9b4fd.jpg\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/919\/5db\/c02\/9195dbc022a87fa469104c26f9b2ba3e.jpg\"\/><\/p>\n<p>  \u0414\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0438\u043f nvarchar(n), \u0433\u0434\u0435 n \u2013 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438, \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0442 50 \u0434\u043e 500. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f nvarchar(MAX). <\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/be4\/5cd\/e77\/be45cde770889a42b93fa93c00f88c9b.jpg\"\/><\/p>\n<p>  \u0417\u0430\u0434\u0430\u0435\u043c \u0434\u043b\u044f ID \u0430\u0432\u0442\u043e\u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/9f6\/5cf\/52c\/9f65cf52c4706e759043c69eda48a8d2.jpg\"\/><\/p>\n<p>  \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 User:  <\/p>\n<table>\n<tr>\n<td><b>\u041f\u043e\u043b\u0435<\/b><\/td>\n<td><b>\u0422\u0438\u043f \u043f\u043e\u043b\u044f<\/b><\/td>\n<\/tr>\n<tr>\n<td>ID<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>Email<\/td>\n<td>nvarchar(150)<\/td>\n<\/tr>\n<tr>\n<td>Password<\/td>\n<td>nvarchar(50)<\/td>\n<\/tr>\n<tr>\n<td>AddedDate<\/td>\n<td>datetime<\/td>\n<\/tr>\n<tr>\n<td>ActivatedDate<\/td>\n<td>datetime (null)<\/td>\n<\/tr>\n<tr>\n<td>ActivatedLink<\/td>\n<td>nvarchar(50)<\/td>\n<\/tr>\n<tr>\n<td>LastVisitDate<\/td>\n<td>datetime (null)<\/td>\n<\/tr>\n<tr>\n<td>AvatarPath<\/td>\n<td>nvarchar(150) (null)<\/td>\n<\/tr>\n<\/table>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 UserRole:  <\/p>\n<table>\n<tr>\n<td><b>\u041f\u043e\u043b\u0435<\/b><\/td>\n<td><b>\u0422\u0438\u043f \u043f\u043e\u043b\u044f<\/b><\/td>\n<\/tr>\n<tr>\n<td>ID<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>UserID<\/td>\n<td>int<\/td>\n<\/tr>\n<tr>\n<td>RoleID<\/td>\n<td>int<\/td>\n<\/tr>\n<\/table>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u044f\u0437\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/977\/523\/7c7\/9775237c7298fb756f72f2b1b65ada27.jpg\"\/><\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0432\u044f\u0437\u044c, \u043d\u0430\u0436\u0430\u0432 Add. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0438. \u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u043a\u043b\u0430\u0434\u043a\u0443 Tables and Columns \u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c, \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 UserRole.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d63\/560\/927\/d6356092752310ea3112a40a3baca81d.jpg\"\/><\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 INSERT And UPDATE Specification \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c On Update\/On Delete \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 Cascade:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ca3\/1c3\/0b1\/ca31c30b160b97646259d5d91b05b230.jpg\"\/><\/p>\n<p>  \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Role \u0432\u0441\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b UserRole \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u044b. <\/p>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 User. <\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0442\u0430\u0431\u043b\u0438\u0446\u044b Role \u0438 User \u0438\u043c\u0435\u044e\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 UserRole. \u0422.\u0435. \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0439 \u0440\u043e\u043b\u0438, \u0438 \u043e\u0434\u043d\u0430 \u0438 \u0442\u0430 \u0436\u0435 \u0440\u043e\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<h5>SELECT, INSERT, UPDATE, DELETE.<\/h5>\n<p>  \u0412 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0431\u0430\u0437\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 SQL.<\/p>\n<p>  \u0415\u0441\u0442\u044c 4 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u2014 SELECT, INSERT, UPDATE, DELETE<\/p>\n<p>  SELECT \u2013 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"sql\">SELECT * FROM User <\/code><\/pre>\n<p>  INSERT \u2014 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"sql\">INSERT INTO Role (Code, Name) VALUES (\u201cadmin\u201d, \u201c\u0410\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u201d) <\/code><\/pre>\n<p>  UPDATE \u2013 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"sql\">UPDATE User SET Password=\u201dpassword1\u201d  WHERE ID=1 <\/code><\/pre>\n<p>  DELETE \u2013 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"sql\">DELETE FROM User WHERE ID =1 <\/code><\/pre>\n<p>  <i>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c SQL \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c:<\/i><br \/>  <a href=\"http:\/\/www.w3schools.com\/sql\/\">http:\/\/www.w3schools.com\/sql\/<\/a><br \/>  <a href=\"http:\/\/codingcraft.ru\/sql_queries.php\">http:\/\/codingcraft.ru\/sql_queries.php<\/a><\/p>\n<h5>LinqToSQL \u0438 Linq.<\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 LessonProject.Model \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414 \u0442\u0438\u043f\u0430 ClassLibrary.<br \/>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c LINQ to SQL Classes \u0442\u0438\u043f, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c LessonProejctDb.dbml<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/195\/475\/c0b\/195475c0bd21d33c677474644617f589.jpg\"\/><\/p>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043c\u044b\u0448\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043d\u0430 \u0445\u043e\u043b\u0441\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/197\/b26\/686\/197b26686844001ee91fbdf967dbcc21.jpg\"\/><\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:  <\/p>\n<ul>\n<li>\u043a\u043b\u0430\u0441\u0441\u044b, \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0411\u0414<\/li>\n<li>\u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0441\u0432\u044f\u0437\u0435\u0439<\/li>\n<\/ul>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Role \u0438 User:<\/p>\n<table>\n<tr>\n<td>1<\/td>\n<td>admin<\/td>\n<td>\u0410\u0434\u043c\u0438\u043d<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>customer<\/td>\n<td>\u0417\u0430\u043a\u0430\u0437\u0447\u0438\u043a<\/td>\n<\/tr>\n<\/table>\n<table>\n<tr>\n<td>1<\/td>\n<td>chernikov@gmail.com<\/td>\n<td>123456<\/td>\n<td>1\/1\/2012 12:00:00 AM<\/td>\n<td>NULL<\/td>\n<td>123456<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>chernikov2@gmail.com<\/td>\n<td>123456<\/td>\n<td>1\/1\/2012 12:00:00 AM<\/td>\n<td>NULL<\/td>\n<td>123456<\/td>\n<td>NULL<\/td>\n<td>NULL<\/td>\n<\/tr>\n<\/table>\n<p>  \u0418 UserRole<\/p>\n<table>\n<tr>\n<td><b>ID<\/b><\/td>\n<td><b>UserID<\/b><\/td>\n<td><b>RoleID<\/b><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>2<\/td>\n<td>2<\/td>\n<\/tr>\n<\/table>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 Lesson3 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c LessonProject.Model. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0431\u043e\u0440\u043a\u0443 System.Configuration \u0438 System.Data.Linq. \u041f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c context \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0440\u043e\u043b\u044f\u0445:  <\/p>\n<pre><code class=\"cs\">    class Program     {         static void Main(string[] args)         {             var context = new LessonProjectDbDataContext(ConfigurationManager.ConnectionStrings[&quot;ConnectionString&quot;].ConnectionString);       var roles = context.Roles.ToList();             foreach (var role in roles)             {                 Console.WriteLine(&quot;{0} {1} {2}&quot;, role.ID, role.Code, role.Name);             }             Console.ReadLine();         }     } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 Role \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a:   <\/p>\n<pre><code class=\"cs\">var newRole = new Role             {                 Code = &quot;manager&quot;,                  Name = &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;             };             context.Roles.InsertOnSubmit(newRole);             context.Roles.Context.SubmitChanges(); <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 Role \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a:   <\/p>\n<pre><code class=\"cs\">var role = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).FirstOrDefault();          if (role != null)          {             context.Roles.DeleteOnSubmit(role);             context.Roles.Context.SubmitChanges();          } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cs\">var role = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).FirstOrDefault();        if (role != null)        {            role.Name = &quot;\u041c\u0430\u043d\u0430\u0433\u0435\u0440&quot;;            context.Roles.Context.SubmitChanges();        } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 Linq. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Linq. Linq \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IQueryable&lt;&gt;<\/p>\n<ul>\n<li><b>.Where() <\/b>\u2013 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f IQueryable. \u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0431\u0443\u043b\u0435\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (bool).<br \/> \n<pre><code class=\"cs\">var roles = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;)  <\/code><\/pre>\n<p>  <\/li>\n<li><b>.FirstOrDefault() \u2014 .First(), .Single(), .SingleOrDefault()<\/b> \u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043f\u0435\u0440\u0432\u0443\u044e \u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c. \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u0442, \u0442\u043e FirstOrDefault() \u0438\u043b\u0438 SingleOrDefault() \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 null (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 [default(int)], \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440).<br \/> \n<pre><code class=\"cs\"> var roles = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).FirstOrDefault() <\/code><\/pre>\n<p> \u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e (\u0438\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c) \u0440\u043e\u043b\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u0443\u044e \u00ab\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u00bb.  <\/li>\n<li><b>.Take()<\/b> \u2013 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 N \u043f\u0435\u0440\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<br \/> \n<pre><code class=\"cs\">var roles = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).Take(4)  <\/code><\/pre>\n<p>\u2013 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 4 \u043f\u0435\u0440\u0432\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438  <\/li>\n<li><b>.Skip()<\/b> \u2013 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 N \u043f\u0435\u0440\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<br \/> \n<pre><code class=\"cs\">var roles = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;). Skip(2).Take(3) <\/code><\/pre>\n<p> \u2013 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 2 \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u0442 3 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438  <\/li>\n<li><b>.OrderBy() <\/b>\u2013 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e. \u0410 \u0442\u0430\u043a\u0436\u0435 OrderByDescending(), ThenBy(), ThenByDescending(). \u041b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0442\u0438\u043f int, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430.<br \/> \n<pre><code class=\"cs\">var roles = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).OrderBy(p =&gt; p.ID)  <\/code><\/pre>\n<p>\u2013 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443  <\/li>\n<li>.Count() \u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439<br \/> \n<pre><code class=\"cs\">var rolesCount = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).Count() <\/code><\/pre>\n<p> \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439  <\/li>\n<li><b>.Any() <\/b>\u2013 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0434\u043d\u0430 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e<br \/>  var rolesExist = context.Roles.Where(p =&gt; p.Name == \u00ab\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u00bb).Any() \u2013 \u0435\u0441\u0442\u044c \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0430\u043a\u0430\u044f  <\/li>\n<li><b>. Select() <\/b>\u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 IQueryable \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 dynamic:<br \/> \n<pre><code class=\"cs\">var otherRole = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).Select(p =&gt; new { ID = p.ID, Kod = p.Code})  <\/code><\/pre>\n<p>\u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Role.  <\/li>\n<li><b>.SelectMany() <\/b>\u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 IQueryable \u0442\u0438\u043f\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<br \/> \n<pre><code class=\"cs\">var otherRole = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).SelectMany(p =&gt; p.UserRoles)  <\/code><\/pre>\n<p>\u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 UserRole \u0438\u0437 \u0440\u043e\u043b\u0438, \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0439 \u00ab\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u00bb  <\/li>\n<li><b>.Distinct()<\/b> \u2013 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b<br \/> \n<pre><code class=\"cs\">var managers = context.Roles.Where(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;).SelectMany(p =&gt; p.UserRoles).Select(p =&gt; p.User).Distinct() <\/code><\/pre>\n<p> \u2013 \u0432\u0441\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441 \u0440\u043e\u043b\u044c\u044e \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0439 \u00ab\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u00bb  <\/li>\n<\/ul>\n<p>  <i>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <code>First(), FirstOrDefault(), Single(), SingleOrDefault(), Any(), Count() <\/code>\u2013 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>Where()<\/code>, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c:<\/i>  <\/p>\n<pre><code class=\"cs\">var roles = context.Roles.FirstOrDefault(p =&gt; p.Name == &quot;\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440&quot;) <\/code><\/pre>\n<p>  <i>\u0411\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f linq \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438:<br \/>  <a href=\"http:\/\/code.msdn.microsoft.com\/101-LINQ-Samples-3fb9811b\">http:\/\/code.msdn.microsoft.com\/101-LINQ-Samples-3fb9811b<\/a><br \/>  <\/i><\/p>\n<h5>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f IRepository, SqlRepository.<\/h5>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 \u0411\u0414 \u043c\u044b \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0442.\u0435. \u043d\u0430\u0448\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043f\u0440\u043e context \u0438 System.Data.Linq \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u043d\u0430\u0442\u044c.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IRepository, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<pre><code class=\"cs\">    public interface IRepository     {         IQueryable&lt;Role&gt; Roles { get; }          bool CreateRole(Role instance);          bool UpdateRole(Role instance);          bool RemoveRole(int idRole);        \t\u2026       } <\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430\u0437\u043e\u0432\u0435\u043c SqlRepository. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u043c SqlRepository \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043e\u0441\u043e\u0431\u043e \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c Ninject \u043c\u043e\u0434\u0443\u043b\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 LessonProject.Model:  <\/p>\n<pre><code class=\"bash\">Install-Package Ninject <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 SqlRepository:<\/p>\n<pre><code class=\"cs\"> public class SqlRepository : IRepository     {         [Inject]         public LessonProjectDbDataContext Db { get; set; }          public IQueryable&lt;Role&gt; Roles         {             get { throw new NotImplementedException(); }         }          public bool CreateRole(Role instance)         {             throw new NotImplementedException();         }          public bool UpdateRole(Role instance)         {             throw new NotImplementedException();         }          public bool RemoveRole(int idRole)         {             throw new NotImplementedException();         }     } <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043f\u043e\u0434\u0443\u043c\u0430\u0435\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0444\u0430\u0439\u043b \u044d\u0442\u043e\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0433\u0440\u043e\u043c\u0430\u0434\u043d\u044b\u043c \u0438 \u043d\u0435\u0443\u043a\u043b\u044e\u0436\u0438\u043c. \u0422\u0430\u043a\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u044f\u0436\u0435\u043b\u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438. \u0422\u0430\u043a \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443 SqlRepository \u0438 SqlRepository \u043a\u043b\u0430\u0441\u0441 \u0441\u0434\u0435\u043b\u0430\u0435\u043c partial, \u0430 \u0432 \u043f\u0430\u043f\u043a\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 IRepository, \u0440\u0430\u0437\u0431\u0438\u0442\u044b\u0435 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u0444\u0430\u0439\u043b Role:<\/p>\n<pre><code class=\"cs\"> public partial class SqlRepository     {         public IQueryable&lt;Role&gt; Roles         {             get             {                 return Db.Roles;             }         }          public bool CreateRole(Role instance)         {             if (instance.ID == 0)             {                 Db.Roles.InsertOnSubmit(instance);                 Db.Roles.Context.SubmitChanges();                 return true;             }              return false;         }          public bool RemoveRole(int idRole)         {             Role instance = Db.Roles.FirstOrDefault(p =&gt; p.ID == idRole);             if (instance != null)             {                 Db.Roles.DeleteOnSubmit(instance);                 Db.Roles.Context.SubmitChanges();                 return true;             }              return false;         }     } <\/code><\/pre>\n<p>  \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0442 10 \u0434\u043e 40 \u0442\u0430\u0431\u043b\u0438\u0446, \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043e\u0442 40, \u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043a\u0430\u043a-\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u043e\u0432, \u0434\u043b\u044f IRepository \u0438 \u0434\u043b\u044f SqlRepository. \u0421\u043d\u0438\u043f\u043f\u0435\u0442\u044b \u2013 \u044d\u0442\u043e \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e intelliSence, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0434. <\/p>\n<h5>\u0421\u043d\u0438\u043f\u043f\u0435\u0442\u044b<\/h5>\n<p>  \u0414\u043b\u044f IRepository \u0442\u0430\u0431\u043b\u0438\u0446, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c table.snippet:  <\/p>\n<pre><code class=\"xml\">&lt;CodeSnippets     xmlns=&quot;http:\/\/schemas.microsoft.com\/VisualStudio\/2005\/CodeSnippet&quot;&gt;   &lt;CodeSnippet Format=&quot;1.0.0&quot; &gt;     &lt;Header&gt;       &lt;Title&gt;         Table       &lt;\/Title&gt;       &lt;Shortcut&gt;Table&lt;\/Shortcut&gt;     &lt;\/Header&gt;     &lt;Snippet&gt;       &lt;Declarations&gt;         &lt;Literal&gt;           &lt;ID&gt;Table&lt;\/ID&gt;           &lt;ToolTip&gt;Table name for create.&lt;\/ToolTip&gt;           &lt;Default&gt;Table&lt;\/Default&gt;         &lt;\/Literal&gt;       &lt;\/Declarations&gt;        &lt;Code Language=&quot;CSharp&quot;&gt;         &lt;![CDATA[ \t\t#region $Table$          IQueryable&lt;$Table$&gt; $Table$s { get; }          bool Create$Table$($Table$ instance);          bool Update$Table$($Table$ instance);          bool Remove$Table$(int id$Table$);          #endregion          ]]&gt;       &lt;\/Code&gt;     &lt;\/Snippet&gt;   &lt;\/CodeSnippet&gt; &lt;\/CodeSnippets&gt;  <\/code><\/pre>\n<p>  \u0414\u043b\u044f SqlRepository \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043d\u0438\u043f\u043f\u0435\u0442 sqlTable.snippet:  <\/p>\n<pre><code class=\"xml\">&lt;CodeSnippets     xmlns=&quot;http:\/\/schemas.microsoft.com\/VisualStudio\/2005\/CodeSnippet&quot;&gt;   &lt;CodeSnippet Format=&quot;1.0.0&quot; &gt;     &lt;Header&gt;       &lt;Title&gt;         Sql repository       &lt;\/Title&gt;       &lt;Shortcut&gt;sqltable&lt;\/Shortcut&gt;     &lt;\/Header&gt;     &lt;Snippet&gt;       &lt;Declarations&gt;         &lt;Literal&gt;           &lt;ID&gt;Table&lt;\/ID&gt;           &lt;ToolTip&gt;Table name for create.&lt;\/ToolTip&gt;           &lt;Default&gt;Table&lt;\/Default&gt;         &lt;\/Literal&gt;       &lt;\/Declarations&gt;        &lt;Code Language=&quot;CSharp&quot;&gt;         &lt;![CDATA[                  public IQueryable&lt;$Table$&gt; $Table$s         {             get             {                 return Db.$Table$s;             }         }          public bool Create$Table$($Table$ instance)         {             if (instance.ID == 0)             {                 Db.$Table$s.InsertOnSubmit(instance);                 Db.$Table$s.Context.SubmitChanges();                 return true;             }              return false;         }          public bool Update$Table$($Table$ instance)         {             $Table$ cache = Db.$Table$s.Where(p =&gt; p.ID == instance.ID).FirstOrDefault();             if (cache != null)             {                 \/\/TODO : Update fields for $Table$                 Db.$Table$s.Context.SubmitChanges();                 return true;             }              return false;         }          public bool Remove$Table$(int id$Table$)         {             $Table$ instance = Db.$Table$s.Where(p =&gt; p.ID == id$Table$).FirstOrDefault();             if (instance != null)             {                 Db.$Table$s.DeleteOnSubmit(instance);                 Db.$Table$s.Context.SubmitChanges();                 return true;             }              return false;         }         ]]&gt;       &lt;\/Code&gt;     &lt;\/Snippet&gt;   &lt;\/CodeSnippet&gt; &lt;\/CodeSnippets&gt;  <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c code-snippet. \u043e\u0442\u043a\u0440\u043e\u0435\u043c TOOLS -&gt; Code Snippet Manager\u2026 (Ctrl-K, B). \u0412 \u043e\u043a\u043d\u0435 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c Import \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0430 \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0430 \u0432 My Code snippet:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/309\/8db\/cb9\/3098dbcb9427a1421b6f99324c28edcd.jpg\"\/><\/p>\n<p>  Finish, OK.<br \/>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 User \u0438 UserRole. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/69d\/040\/b4b\/69d040b4b66a0edf72a6620108019bc6.jpg\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/9e2\/c66\/479\/9e2c6647903083b0f1183aade33b6319.jpg\"\/><\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044f \u0434\u043b\u044f <code>Update<\/code> [\u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b], \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<h5>Proxy<\/h5>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f partial, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c, \u043f\u043e\u0434\u043e\u0431\u043d\u043e SqlRepository, \u043f\u0430\u043f\u043a\u0443 Proxy, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c partial \u043a\u043b\u0430\u0441\u0441\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 User \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u0443\u044e \u0434\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:  <\/p>\n<pre><code class=\"cs\"> public partial class User     {         public static string GetActivateUrl()         {             return Guid.NewGuid().ToString(&quot;N&quot;);         }     } <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e:  <\/p>\n<pre><code class=\"cs\">public bool CreateUser(User instance)         {             if (instance.ID == 0)             {                 instance.AddedDate = DateTime.Now;                 instance.ActivatedLink = User.GetActivateUrl();                 Db.Users.InsertOnSubmit(instance);                 Db.Users.Context.SubmitChanges();                 return true;             }              return false;         } <\/code><\/pre>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0411\u0414 \u0432 asp.net mvc<\/h5>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0411\u0414 \u0432 web.Config:  <\/p>\n<pre><code class=\"xml\">&lt;connectionStrings&gt;     &lt;add name=&quot;ConnectionString&quot; connectionString=&quot;Data Source=SATURN-PC;Initial Catalog=LessonProject;Integrated Security=True;Pooling=False&quot; providerName=&quot;System.Data.SqlClient&quot; \/&gt;   &lt;\/connectionStrings&gt;  <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0411\u0414 \u0432 Ninject:  <\/p>\n<pre><code class=\"cs\">  private static void RegisterServices(IKernel kernel)         {             kernel.Bind&lt;LessonProjectDbDataContext&gt;().ToMethod(c =&gt; new LessonProjectDbDataContext(ConfigurationManager.ConnectionStrings[&quot;ConnectionString&quot;].ConnectionString));             kernel.Bind&lt;IRepository&gt;().To&lt;SqlRepository&gt;().InRequestScope();         }       <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c InRequestScope(). \u0422.\u0435. \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 SqlRepository. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438.\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c IRepository \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:   <\/p>\n<pre><code class=\"cs\">  public class HomeController : Controller     {         [Inject]         public IRepository Repository { get; set; }          public ActionResult Index()         {             var roles = Repository.Roles.ToList();             return View(roles);         }     } <\/code><\/pre>\n<p>  \u0418 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c View (\/Views\/Home\/Index.cshtml):  <\/p>\n<pre><code class=\"html\">@model IList&lt;LessonProject.Model.Role&gt; @{     ViewBag.Title = &quot;LessonProject&quot;;     Layout = &quot;~\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;LessonProject&lt;\/h2&gt;  &lt;p&gt;     @foreach (var role in Model)     {         &lt;div class=&quot;item&quot;&gt;             &lt;span class=&quot;id&quot;&gt;                 @role.ID             &lt;\/span&gt;             &lt;span class=&quot;name&quot;&gt;                 @role.Name             &lt;\/span&gt;             &lt;span class=&quot;Code&quot;&gt;                 @role.Code             &lt;\/span&gt;         &lt;\/div&gt;     } &lt;\/p&gt; <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/7e4\/890\/daf\/7e4890daf31d551343fb99e2e49cbdf5.jpg\"\/><\/p>\n<p>  \u0412\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/bitbucket.org\/chernikov\/lessons\">https:\/\/bitbucket.org\/chernikov\/lessons<\/a>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/176017\/\"> http:\/\/habrahabr.ru\/post\/176017\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430<\/b>: \u0418\u0437\u0443\u0447\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446, \u0441\u0432\u044f\u0437\u0435\u0439 \u0432 VS 2012). \u041a\u043e\u043c\u0430\u043d\u0434\u044b INSERT, UPDATE, DELETE, SELECT. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 LinqToSql \u0438 Linq. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u0430\u0440\u0438\u044f, IRepository, SqlRepository.<\/p>\n<h5>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0411\u0414<\/h5>\n<p>  \u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0420\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u2013 \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f (\u0441\u0432\u044f\u0437\u0438) \u043e\u0442 \u0430\u043d\u0433\u043b. relation.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-176017","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176017"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176017\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}