Method not found: Int32 .get_Field2()

Boy does time fly!

This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.

This thread has been locked

This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz

  • Hi,

    I hit a problem when I am querying a table with some null values. The problem occurs when I use LINQ to project a new object. I set some of my properties to a "Nullable" type (those fields I know that will have null values). Could you please shed some light on this or give me some idea on what is happening? Appreciate your help on this. Below is sample of my code.

    Sample Code:

    var comTable = complexTable.SqlQuery(sqlStatement); --> this will return an Enumerable of entities using "FindBySql". I was able to check that it was able to retrieve the records I need.
    var projectValue = comTable .Select( x => 
               new {
                          x.Field1,
                          x.Field2,
                          x.Field3
               });    --> The problem is here throwing "Method not found: Int32 .get_Field2()", it could not seem to find the property that has null values.
    

    Sample Entity:

    [Table("TableName", IdColumnName="FieldId", IdentityMethod = "IdentityMethod .Guid")]
    public class TableName : Entity<Giud>
    {
             private string _field1;
             private Nullable<int> _field2;
             private Nullable<int> _field3;
    
             public string Field1
             {
                  get { return _field1; }
                  set {  Set( ref _field1, value); }
             }
             public Nullable<int> Field2
             {
                  get { return _field2; }
                  set {  Set( ref _field2, value); }
             }
             public Nullable<int> Field3
             {
                  get { return _field3; }
                  set {  Set( ref _field3, value); }
             }
    }
    
  • I seem to find the answer to problem but your thoughts are still welcome. Basically, before I do a projection I converted the output to a "List".

    Something like this:

    var comTable = complexTable.SqlQuery(sqlStatement).ToList();
    var projectValue = comTable .Select( x => 
               new {
                          x.Field1,
                          x.Field2,
                          x.Field3
               });
    

    Just want to know if in lightSpeed it is required to do this before performing any projection? Note that I did the same with other ORM like Entity Framework and NHIbernate and I did NOT get this problem.

    Appreciate your response on this.