tags:

views:

19

answers:

1

Hi,

In my mvc web application, I am getting this error:

Anonymously Hosted DynamicMethods Assembly
Stack Trace : at Read_<>f__AnonymousType14(ObjectMaterializer1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at project.com.Concrete.DetailsRepository.GetDetails(String type) in path
Message : The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.

When I run my site from local server it is working fine. But when it runs at remote server it is giving above error

Here is my code:

var res=
(from r in DetailsTable 
 where r.Activated == true 
 group r by new { r.ActivationDate, r.ProductID, r.SubProductID } into t 
 select new { icount = t.Count(), 
              sActivationDate = t.Key.ActivationDate.ToShortDateString(), 
              iProductID = t.Key.ProductID, 
              iSubProductid = t.Key.SubProductID })
.OrderBy(r => r.icount);

Thanks AS

A: 

The issue you're having is that your query is empty on the remote server where data exists on the local server.

I'm not exactly sure at which part in the query the exception is happening, so I'd suggest splitting your query in half.

var res=
     from r in DetailsTable 
     where r.Activated == true;

if(res.Count() == 0)
  return; // or handle gracefully as appropriate

var groups = 
     from r in res
     group r by new { r.ActivationDate, r.ProductID, r.SubProductID } into t 
     select new { icount = t.Count(), 
                  sActivationDate = t.Key.ActivationDate.ToShortDateString(), 
                  iProductID = t.Key.ProductID, 
                  iSubProductid = t.Key.SubProductID })
    .OrderBy(r => r.icount);

I'm sure there is a more graceful way of doing this within a single query statement, but without more details I'm not sure exactly how to proceed.

Will