سؤال

I have a atribute in model declerated as "int"

[SolrField("statusId")]
public int StatId { get; set; }

This works correctly. But, because this atribute is "INT" it does not return back "NULL" where filed suposed to be empty, instand it returns "0", so my table in view have 0 in fields which should be empty.

I have start code like this:

private int _stId;
[SolrField("statusId")]
public int StartId
{
   get
   {
      if (_stId == 0) // so if it's true if field is 0 
      {
         return new ... // here I must return string {" "}, so if filed is 0 return " "
      }
      else
      {
         return _stId;
      }
   }
   set
   {
      _stId = value;
   }
}
هل كانت مفيدة؟

المحلول

I would simply use the type int? instead of int. Int? is a nullable integer. Take a look at this documentation on how to use it properly: http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx

Update: If you can't change the type, I would create an additional property of type int?

public int? nullableStatId
{ 
    get { StatId == 0 ? return null : return StatId; }
    set { StatId = value; }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top