locked
How use we equal at decimal field in linq dynamic class RRS feed

  • Question

  • Hi

    When I use    "equal " statement   in string filed in linq dynamic class , it works fine ,  But in decimal field , it isn' work . 

    I take an error which is '' Methods on type 'Decimal?' are not accessible"   .

    How do i use "equal"  in decimal or num fied. 

    /////////////////////////////////////////////////////////////////////////////////

     public  class FILTER  

      {       public string QUERY { get; set; }        

       public object[] VALUES { get; set; }  

      }


    /////////////////////////////////////////////////////////////////////////////////


                  try
                  {
                      if (!string.IsNullOrEmpty(jsfilter.QUERY))
                            using (var db = new ZorluEntities())
                            {
                                return (from b in db.TR_CHECKLISTVIEW
                                    where b.TASK == taskCode
                                    orderby b.CODE
                                    select b).Where(jsfilter.QUERY, jsfilter.VALUES).Skip(pageindex*10).Take(10).ToList();

                            }
                      using (var db = new ZorluEntities())
                      {
                          return (from b in db.TR_CHECKLISTVIEW
                              where b.TASK == taskCode
                              orderby b.CODE
                              select b).Skip(pageindex*10).Take(10).ToList();

                      }
                  }
                  catch (Exception exc)
                    {
                        throw new Exception(" RepositoryCheckList : GetCheckList", exc);
                    }

        //////////////////////////////////////////////////////////////////////////////////

    eamples:

    jsfilter.QUERY= "SEQUENCE.Equals(@0)"

    jsfilter.VALUES[0]="4"

    /////////////////////////////////////////////////////////////////////////////////////////

      


    • Edited by tiryakiemre Friday, February 7, 2014 4:04 PM
    Friday, February 7, 2014 3:19 PM

Answers

  • Hello,

    The default implementation of Equals supports reference equality only, but derived classes can override this method to support value equality.

    In this Dynamic Linq Library, we can use it to int and decimal, however, there's no overriden method of the Equals for value types, 'decimal?' type is also a value type, except that it can be null.

    The error shows that the field is decimal? type, then we need to use “==” or “!=”.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    • Unmarked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    Monday, February 10, 2014 7:44 AM
  • Hi Fred Bao,

    I change coming filters query from jquery to c# then , now it is working.

    I do it two filter object : string and int 

    I use   ".contains(@i), object(i).value" in  query of string type

    I use   "SQUENCE=='int expression' " in  query of decimal type.

    codes are here :

    ---------------------------------------------------------------------------------

     $("[data-filter-field]").each(function (e) {
                if ($(this).val() != '') {
                    if ($(this).attr('data-filter-type') == 'stringView')
                        query = query + $(this).attr('data-filter-field') + ".Contains(@" + i + ") AND ";
                    filterValues[i] = $(this).val();
                    i = i + 1;
                }

            });
            $("[data-filter-field]").each(function (e) {
                if ($(this).val() != '') {
                    if ($(this).attr('data-filter-type') == 'stringNum')
                        query = query + $(this).attr('data-filter-field') + "==" + $(this).val() + " AND ";
                    i = i + 1;
                }

            });

    ------------------------------------------------------------------------------------------------

    and  in c#

    ----------------------------------------------------------------------------------------------------
    jsfilter.QUERY="DESCB.Contains(@1) AND SEQUENCE==2 "

    jsfilter.VALUES [0]="2"
    jsfilter.VALUES [1]="Gİ"

    -------------------------------------------------------------------------------------------------------.

    Thanks your solutions.
    • Edited by tiryakiemre Monday, February 10, 2014 4:10 PM
    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    Monday, February 10, 2014 4:10 PM

All replies

  • Hello,

    The default implementation of Equals supports reference equality only, but derived classes can override this method to support value equality.

    In this Dynamic Linq Library, we can use it to int and decimal, however, there's no overriden method of the Equals for value types, 'decimal?' type is also a value type, except that it can be null.

    The error shows that the field is decimal? type, then we need to use “==” or “!=”.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    • Unmarked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    Monday, February 10, 2014 7:44 AM
  • Hi Fred Bao,

    I change coming filters query from jquery to c# then , now it is working.

    I do it two filter object : string and int 

    I use   ".contains(@i), object(i).value" in  query of string type

    I use   "SQUENCE=='int expression' " in  query of decimal type.

    codes are here :

    ---------------------------------------------------------------------------------

     $("[data-filter-field]").each(function (e) {
                if ($(this).val() != '') {
                    if ($(this).attr('data-filter-type') == 'stringView')
                        query = query + $(this).attr('data-filter-field') + ".Contains(@" + i + ") AND ";
                    filterValues[i] = $(this).val();
                    i = i + 1;
                }

            });
            $("[data-filter-field]").each(function (e) {
                if ($(this).val() != '') {
                    if ($(this).attr('data-filter-type') == 'stringNum')
                        query = query + $(this).attr('data-filter-field') + "==" + $(this).val() + " AND ";
                    i = i + 1;
                }

            });

    ------------------------------------------------------------------------------------------------

    and  in c#

    ----------------------------------------------------------------------------------------------------
    jsfilter.QUERY="DESCB.Contains(@1) AND SEQUENCE==2 "

    jsfilter.VALUES [0]="2"
    jsfilter.VALUES [1]="Gİ"

    -------------------------------------------------------------------------------------------------------.

    Thanks your solutions.
    • Edited by tiryakiemre Monday, February 10, 2014 4:10 PM
    • Marked as answer by tiryakiemre Monday, February 10, 2014 4:11 PM
    Monday, February 10, 2014 4:10 PM