Sunday 15 June 2014

c# - The cast to value type 'Int32' failed because the materialized value is null -


I can not understand what is the problem for my life. Every time the query goes to execute "ToList ()", I get the error above

Here's more information on this.

  & lt; Error & gt; & Lt; Message & gt; An error occurred. & Lt; / Messages & gt; & Lt; ExceptionMessage & gt; Cast value in Value Type '32' failed because the physical value is zero. Either the generic parameter or query type of the result should be used in a faucet type & Lt; / ExceptionMessage & gt; & Lt; ExceptionType & gt; System.InvalidOperationException & lt; / ExceptionType & gt; & Lt; StackTrace & gt; System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader1.GetValue (DbDataReader reader, int32 ordinal) at System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling [TColumn] (int32 sequential) at lambda_method (Closer), System Shaper on Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement (Shaper Shaper) on System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext () on System.Linq.Enumerable. WhereEnumerableIterator`1.MoveNext () System.Collections.Generic.List`1..ctor (IEnumerable`1 collection System.Linq.Enumerable.ToList on TVDataWebAPI.Controllers.ETSShowsController) [TSource] (in IEnumerable`1 source). GetETSShows (string title, string episodeTitle, string style, string showTypeDescription, DirectorName string, the string is released, string seasonEpisode) in C: \ Users \ rarbex \ Documents \ Visual Studio 2012 \ Projects \ TVDataWebAPI \ TVDataWebAPI \ controllers \ ETSShowsController.cs: in line Lambda_maleshn 83 (Closure, Objek System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor. & Lt; & gt; c__DisplayClass13. & Lt; GetExecutor & gt; b__c (object instance, object [] method Parameters) system. web. Http.Controllers.ReflectedHttpActionDescriptor on System.Threading.Tasks.TaskHelpers.RunSynchronously [TResul t [on b__4 () (; ActionExecutor.Execute (eg, Commodities]] arguments) on System.Web.Http.Controllers.ReflectedHttpActionDescriptor. & lt; & gt; c__DisplayClass5. & lt; & gt ExecuteAsync Func`1 func , Cancellation token cancellation token) & lt; / StackTrace & gt; & lt; / error> Public IEnumerable & lt; ETSShows & gt; GetETSShows (string title = null; {string episodeTitle = null, string style = null, string ShowTypeDescription = null, string directorName = null, string release = null, string seasonEpisode = null) {IQueryable & LT; ETSShows & gt; Db.ETS_LKP_Genres.Where (in style = & gt; defaultIfEmpty (); from queries show in db.ETS_Episodes.Where (v.ShowId == shows.ShowId V = & gt); from episodes in db.ETS_Shows = s .GenreCode == db.ETS_LKP_ShowTypes.Where in shows.GenreCode) .DefaultIfEmpty () showTypes from (Z = & gt; z.ShowTypeCode == shows.ShowTypeCode) (.DefaultIfEmpty of directors db.ETS_Directors.Where) (p = & gt; P .ShowId == shows.ShowId) .DefaultIfEmpty () new ETSShows {select data source = "ETS" title = shows.Title, EpisodeId = episodes.EpisodeId, EpisodeTitle = episodes.EpisodeTitle, GenreDescription = genres .GenreDescription, ShowTypeDescription = showTypes. ShowTypeDescription, name = directors.Name, release = (int) shows.ReleaseYear, SeasonEpisode = episodes.SeasonEpisode, ShowId = shows.ShowId}; }} Public class ETSShows {public string data source {get; Set; } Public string title {get; Set; } Public Entry Episodes {Received; Set; } Public String EpisodeTitle {get; Set; } Public string GenreDescription {get; Set; } Public string ShowTypeDescription {get; Set; } Public string name {get; Set; } Public Int Relieior {Received; Set; } Public String Season Episode {get; Set; } Public int ShowId {get; Set; }}    

I'm guessing this is right here:

  released = (int) show.ReleaseYear   

Why do you have to show.ReleaseYear for code > Integer ? Is not it already a int ? It may actually be a nullable & lt; integer & gt;

A integer can not stop a a value , and the error is telling you that the data contains a zero < / Code> value, so that the value can not be entered in int .

You do not need to either change your data to allow the null values ​​for that area, or your type is faucetable & lt; Int & gt; (or int? small).

No comments:

Post a Comment