{"id":271172,"date":"2015-12-25T19:21:02","date_gmt":"2015-12-25T16:21:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=271172"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=271172","title":{"rendered":"\u0412\u044b\u0448\u043b\u0430 \u043d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f LinqTestable \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0434 \u0447\u0435\u0440\u0435\u0437 ORM"},"content":{"rendered":"<p>       LinqTestable \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u044b\u0432 \u043c\u0435\u0436\u0434\u0443 \u041e\u041e\u041f \u0438 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0411\u0414, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0439 \u0438\u0437-\u0437\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f NULL-\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 NULL == NULL \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u0443 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0438 \u043b\u043e\u0436\u044c \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, NULL.SomeField \u0432\u0435\u0440\u043d\u0451\u0442 NULL \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442 NullReferenceException \u0432 C#. LinqTestable \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/766\/fac\/30e\/766fac30ef764c5aac471c89d7cb47d7.jpg\"\/><br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0435\u0449\u0451 \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0433\u043e\u0442\u043e\u0432\u0430, \u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e. \u0412 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043d\u0430\u0434 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 OrderBy.<\/p>\n<p>  \u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/FiresShadow\/LinqTestable\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445<\/a> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<h4><b>\u0423\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 NullRefenceException<\/b><\/h4>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043d\u0438\u044f NullRefenceException \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a null.DOOR_ID; \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f null.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    [TestFixture]     public class TwoLeftJoins     {         void ExecuteTwoLeftJoins(bool isSmart)         {             var dataModel = new TestDataModel {Settings = {IsSmart = isSmart}};              const int carId = 100;             dataModel.CAR.AddObject(new CAR{CAR_ID = carId});             dataModel.CAR.AddObject(new CAR{CAR_ID = carId + 1});              var cars =                 (from car in dataModel.CAR                 join door in dataModel.DOOR on car.CAR_ID equals door.CAR_ID                      into joinedDoor from door in joinedDoor.DefaultIfEmpty()                 join doorHandle in dataModel.DOOR_HANDLE on door.DOOR_ID equals doorHandle.DOOR_ID                      into joinedDoorHandle from doorHandle in joinedDoorHandle.DefaultIfEmpty()                 select car).ToList();              Assert.AreEqual(2, cars.Count);             Assert.AreEqual(carId, cars.First().CAR_ID);         }          [Test]         public void TwoLeftJoinsShouldThrow()         {             Assert.Throws&lt;NullReferenceException&gt;(() =&gt; ExecuteTwoLeftJoins(false));         }          [Test]         public void SmartTwoLeftJoinsShouldNotThrow()         {             ExecuteTwoLeftJoins(true);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f NullReferenceException \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 null, \u043d\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b \u0440\u0438\u0441\u043a\u0443\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 SQL \u0438 \u043f\u043b\u0430\u043d \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043e\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e. \u041e\u0431 \u044d\u0442\u043e\u043c \u044f \u043f\u0438\u0441\u0430\u043b \u0432 <a href=\"http:\/\/habrahabr.ru\/post\/269917\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u043e\u0439 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435<\/a>.<\/p>\n<p>  \u0421\u043b\u0443\u0447\u0430\u0439, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 NullReferenceException \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a Value \u0443 Nullable:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    [TestFixture]     public class Contains     {         public void ExecuteContains(bool isSmart)         {             var dataModel = new TestDataModel { Settings = { IsSmart = isSmart } };              new[]             {                 new DOOR_HANDLE {DOOR_HANDLE_ID = 1, MATERIAL_ID = 1},                 new DOOR_HANDLE {DOOR_HANDLE_ID = 2, MATERIAL_ID = 2},                 new DOOR_HANDLE {DOOR_HANDLE_ID = 3, MATERIAL_ID = null}             }                 .ForEach(dataModel.DOOR_HANDLE.AddObject);                         var doorHandleIds = new List&lt;int&gt;{1,2};              var doorHandles =                 (from doorHandle in dataModel.DOOR_HANDLE                 where doorHandleIds.Contains(doorHandle.MATERIAL_ID.Value)                 select doorHandle).ToList();              Assert.AreEqual(2, doorHandles.Count);         }          [Test]         public void ContainsShouldFail()         {             Assert.Throws&lt;InvalidOperationException&gt;(() =&gt; ExecuteContains(false));         }          [Test]         public void SmartContainsShouldSuccess()         {             ExecuteContains(true);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4><b>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 Sum<\/b><\/h4>\n<p>  \u041c\u0435\u0442\u043e\u0434 Sum \u0432\u0435\u0434\u0451\u0442 \u0441\u0435\u0431\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432 C# \u043d\u0430\u0434 \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0443\u043c\u043c\u044b \u043e\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 NULL, \u0430 \u0432 \u0421# \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f 0. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0443\u043c\u043c\u044b, \u0431\u044b\u043b\u043e \u043d\u0435 Nullable&lt;&gt;, \u0442\u043e ORM \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 LinqTestable, Sum \u0438\u043b\u0438 \u0432\u0435\u0440\u043d\u0451\u0442 NULL, \u0438\u043b\u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    [TestFixture]     public class SumFromEmptyTable     {         void ExecuteSumFromEmptyTable(bool isSmart)         {             var dataModel = new TestDataModel {Settings = {IsSmart = isSmart}};             int sum = dataModel.CAR.Sum(x =&gt; x.CAR_ID);         }          [Test]         public void SmartSumShouldThrow()         {             Assert.Throws&lt;InvalidOperationException&gt;(() =&gt; ExecuteSumFromEmptyTable(true));         }          [Test]         public void SumShouldNotThrow()         {             ExecuteSumFromEmptyTable(false);         }          void ExecuteNullableSumFromEmptyTable(bool isSmart)         {             var dataModel = new TestDataModel { Settings = { IsSmart = isSmart } };             int? sum = dataModel.DOOR_HANDLE.Sum(x =&gt; x.MATERIAL_ID);             Assert.AreEqual(null, sum);         }          [Test]         public void NullableSumShouldFail()         {             Assert.Throws&lt;AssertionException&gt;(() =&gt; ExecuteNullableSumFromEmptyTable(false));         }          [Test]         public void NullableSmartSumShouldSuccess()         {             ExecuteNullableSumFromEmptyTable(true);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4><b>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 null == null<\/b><\/h4>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 LinqTestable, null == null \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c false, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u044f\u0432\u043d\u043e \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0447\u0435\u0433\u043e \u0442\u043e \u0441 null, \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">    [TestFixture]     public class NullComparison     {         void ExecuteNullComparison(bool isSmart)         {             var dataModel = new TestDataModel { Settings = { IsSmart = isSmart } };              new[]             {                 new DOOR_HANDLE {DOOR_HANDLE_ID = 1, MATERIAL_ID = 1, MANUFACTURER_ID = 1}, \/\/ &lt;----                 new DOOR_HANDLE {DOOR_HANDLE_ID = 2, MATERIAL_ID = 2, MANUFACTURER_ID = 2}, \/\/      |-- this is only pair                 new DOOR_HANDLE {DOOR_HANDLE_ID = 3, MATERIAL_ID = 1, MANUFACTURER_ID = 1}, \/\/ &lt;----                 new DOOR_HANDLE {DOOR_HANDLE_ID = 4, MATERIAL_ID = 5, MANUFACTURER_ID = null},                 new DOOR_HANDLE {DOOR_HANDLE_ID = 5, MATERIAL_ID = 5, MANUFACTURER_ID = null},                 new DOOR_HANDLE {DOOR_HANDLE_ID = 6, MATERIAL_ID = null, MANUFACTURER_ID = null},                 new DOOR_HANDLE {DOOR_HANDLE_ID = 7, MATERIAL_ID = null, MANUFACTURER_ID = null}             }             .ForEach(x =&gt; dataModel.DOOR_HANDLE.AddObject(x));              var handlePairsWithSameMaterialAndManufacturer =                (from handle in dataModel.DOOR_HANDLE                 join anotherHandle in dataModel.DOOR_HANDLE on handle.MATERIAL_ID equals anotherHandle.MATERIAL_ID                 where handle.MANUFACTURER_ID == anotherHandle.MANUFACTURER_ID && handle.DOOR_HANDLE_ID &lt; anotherHandle.DOOR_HANDLE_ID                 select new {handle, anotherHandle}).ToList();              Assert.AreEqual(1, handlePairsWithSameMaterialAndManufacturer.Count);             var pair = handlePairsWithSameMaterialAndManufacturer.First();             Assert.AreEqual(1, pair.handle.MATERIAL_ID);             Assert.AreEqual(pair.handle.MATERIAL_ID, pair.anotherHandle.MATERIAL_ID);             Assert.AreEqual(1, pair.handle.MANUFACTURER_ID);             Assert.AreEqual(pair.handle.MANUFACTURER_ID, pair.anotherHandle.MANUFACTURER_ID);         }          [Test]         public void NullComparisonShouldFail()         {             Assert.Throws&lt;AssertionException&gt;(() =&gt; ExecuteNullComparison(false));         }          [Test]         public void SmartNullComparisonShouldSuccess()         {             ExecuteNullComparison(true);         }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h4><b>\u041a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/b><\/h4>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u043c\u0443 \u041f\u041e \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u00ab\u043a\u0430\u043a \u0435\u0441\u0442\u044c\u00bb (as is, no warranty). \u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Nuget.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/7fd\/e1a\/6ef\/7fde1a6ef3ef4392be38219a1f20be17.png\"\/><\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c ObjectSet \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432 Expression \u0438 Provider \u043d\u0430:<\/p>\n<pre><code class=\"cs\">        public System.Linq.Expressions.Expression Expression         {             get { return _collection.AsQueryable&lt;T&gt;().ToTestable().Expression; }         }          public IQueryProvider Provider         {             get { return _collection.AsQueryable&lt;T&gt;().ToTestable().Provider; }         } <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\\\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f LinqTestable<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">        public Expression Expression         {             get             {                 return                      _settings.IsSmart ?                     _collection.AsQueryable().ToTestable().Expression :                      _collection.AsQueryable().Expression;             }         }          public IQueryProvider Provider         {             get {                      return                         _settings.IsSmart ?                         _collection.AsQueryable().ToTestable().Provider :                          _collection.AsQueryable().Provider;               }         } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043a \u043d\u0435\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0430 LinqTestable \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u0441\u0430\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/FiresShadow\/LinqTestable\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438<\/a>.<\/p>\n<p>  \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0432\u043e\u0442 <a href=\"http:\/\/www.codeproject.com\/Articles\/447988\/How-to-Mock-Test-an-Entity-Framework-Model-First-P\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Entity Framework.<\/p>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u043e\u0439 (OrderBy), \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u043b\u043a\u0438\u0445 \u043d\u0435\u0434\u043e\u0447\u0451\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u0422\u0430\u043a\u0436\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A0%D0%B5%D1%84%D0%B0%D0%BA%D1%82%D0%BE%D1%80%D0%B8%D0%BD%D0%B3\">\u043f\u043e\u0440\u0435\u0444\u0430\u0447\u0438\u0442\u044c<\/a> \u043a\u043e\u0434.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u0435 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0431\u0430\u0433\u0438 \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0431\u0434 \u0438 \u0432 C# \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u2014 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438\u0448\u043b\u0451\u0442\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0439 unit-\u0442\u0435\u0441\u0442 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 LinqTestable@mail.ru               <\/p>\n<div class=\"clear\"><\/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\/273801\/\"> http:\/\/habrahabr.ru\/post\/273801\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       LinqTestable \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u044b\u0432 \u043c\u0435\u0436\u0434\u0443 \u041e\u041e\u041f \u0438 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0411\u0414, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0439 \u0438\u0437-\u0437\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f NULL-\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 NULL == NULL \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0441\u0442\u0438\u043d\u0443 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0438 \u043b\u043e\u0436\u044c \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e, NULL.SomeField \u0432\u0435\u0440\u043d\u0451\u0442 NULL \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442 NullReferenceException \u0432 C#. LinqTestable \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/766\/fac\/30e\/766fac30ef764c5aac471c89d7cb47d7.jpg\"\/>  <\/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-271172","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/271172","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=271172"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/271172\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=271172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=271172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=271172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}