{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4012","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4012/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4012/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4012/events","html_url":"https://github.com/aspnet/EntityFramework/issues/4012","id":121116735,"number":4012,"title":"InvalidCastException for Nullable<DateTime> in dnxcore50 but not dnx451 (RC1)","user":{"login":"mguinness","id":14002844,"avatar_url":"https://avatars.githubusercontent.com/u/14002844?v=3","gravatar_id":"","url":"https://api.github.com/users/mguinness","html_url":"https://github.com/mguinness","followers_url":"https://api.github.com/users/mguinness/followers","following_url":"https://api.github.com/users/mguinness/following{/other_user}","gists_url":"https://api.github.com/users/mguinness/gists{/gist_id}","starred_url":"https://api.github.com/users/mguinness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mguinness/subscriptions","organizations_url":"https://api.github.com/users/mguinness/orgs","repos_url":"https://api.github.com/users/mguinness/repos","events_url":"https://api.github.com/users/mguinness/events{/privacy}","received_events_url":"https://api.github.com/users/mguinness/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-08T22:41:11Z","updated_at":"2015-12-10T02:47:26Z","closed_at":null,"body":"Getting an InvalidCastException when using EntityFramework.MicrosoftSqlServer (7.0.0-rc1-final) but only in Core-CLR not Full-CLR.\r\n\r\nColumn definition is:\r\n`[ApprovedDate] [datetime2](7) NULL`\r\n\r\nClass definition is:\r\n`public DateTime? ApprovedDate { get; set; }`\r\n\r\nI found a similar issue at https://github.com/aspnet/EntityFramework/issues/2596 but unsure if it's related.\r\n\r\nFull error shown below:\r\n\r\n`Microsoft.Data.Entity.Query.Internal.QueryCompiler: An exception occurred in the database while iterating the results of a query. System.InvalidCastException: Cannot cast from source type to destination type.\r\n  at System.Nullable'1<System.DateTime>.Unbox (object) <0x00060>\r\n  at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Data.Entity.Storage.ValueBuffer) <0x000cd>\r\n  at Microsoft.Data.Entity.Query.EntityLoadInfo.Materialize () <0x00037>\r\n  at Microsoft.Data.Entity.Query.Internal.QueryBuffer.GetEntity (Microsoft.Data.Entity.Infrastructure.IKeyValue,Microsoft.Data.Entity.Query.EntityLoadInfo,bool) <0x000c3>\r\n  at Microsoft.Data.Entity.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.CreateEntity<Portal.Models.Content> (Remotion.Linq.Clauses.IQuerySource,Microsoft.Data.Entity.Storage.ValueBuffer,int,Microsoft.Data.Entity.Query.QueryContext,Microsoft.Data.Entity.Metadata.IEntityType,bool,Microsoft.Data.Entity.ChangeTracking.Internal.KeyValueFactory,System.Func'2<Microsoft.Data.Entity.Storage.ValueBuffer, object>,bool,bool) <0x0016a>\r\n  at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Data.Entity.Storage.ValueBuffer) <0x001ee>\r\n  at System.Linq.Enumerable/<CreateSelectIterator>c__Iterator10'2<Microsoft.Data.Entity.Storage.ValueBuffer, Portal.Models.Content>.MoveNext () <0x0017e>\r\n  at System.Linq.Enumerable.First<Portal.Models.Content> (System.Collections.Generic.IEnumerable'1<Portal.Models.Content>,System.Func'2<Portal.Models.Content, bool>,System.Linq.Enumerable/Fallback) <0x000af>\r\n  at System.Linq.Enumerable.FirstOrDefault<Portal.Models.Content> (System.Collections.Generic.IEnumerable'1<Portal.Models.Content>) <0x0005f>\r\n  at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Data.Entity.Query.QueryContext) <0x00286>\r\n  at Microsoft.Data.Entity.Query.Internal.QueryCompiler/<>c__DisplayClass18_1'1<Portal.Models.Content>.<CompileQuery>b__1 (Microsoft.Data.Entity.Query.QueryContext) <0x00033>`"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/163468656","html_url":"https://github.com/aspnet/EntityFramework/issues/4012#issuecomment-163468656","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4012","id":163468656,"user":{"login":"mguinness","id":14002844,"avatar_url":"https://avatars.githubusercontent.com/u/14002844?v=3","gravatar_id":"","url":"https://api.github.com/users/mguinness","html_url":"https://github.com/mguinness","followers_url":"https://api.github.com/users/mguinness/followers","following_url":"https://api.github.com/users/mguinness/following{/other_user}","gists_url":"https://api.github.com/users/mguinness/gists{/gist_id}","starred_url":"https://api.github.com/users/mguinness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mguinness/subscriptions","organizations_url":"https://api.github.com/users/mguinness/orgs","repos_url":"https://api.github.com/users/mguinness/repos","events_url":"https://api.github.com/users/mguinness/events{/privacy}","received_events_url":"https://api.github.com/users/mguinness/received_events","type":"User","site_admin":false},"created_at":"2015-12-10T02:47:26Z","updated_at":"2015-12-10T02:47:26Z","body":"I've been digging into this a bit more.  It appears that this is an issue w/ datetime2 and not datetime, the latter has no issues.  Also if I set the value to null it works and it only breaks when non-null.  Even though this is for Dapper and not EF, a similar issue is reported at https://github.com/StackExchange/dapper-dot-net/issues/295."}}