You must Sign In to post a response.
  • Category: LINQ

    Please tell me how to solve this issue

    Hi All,

    I am getting an error that is i am not able to under stand.
    my error:-

    Message: LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' method, and this method cannot be translated into a store expression.
    Type: System.NotSupportedException
    Source: System.Data.Entity
    Site: Translate
    Stack Trace:
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
    at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
    at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
    at System.Data.Objects.ELinq.ExpressionConverter.Convert()
    at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
    at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
    at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
    at System.Data.Objects.ObjectQuery`1.GetEnumeratorInternal()
    at System.Data.Objects.ObjectQuery.System.Collections.IEnumerable.GetEnumerator()
    at #=qf_8CePnBDTQrfDWHHp4IV$cZMyjsiL9AKJwRVf52NLmcZQJp8kYTwB2V61ObkaTr.#=q6iOvHurbHbY90C7J$z9Bzw==(IEnumerable #=qMwCQ8Yqcn0QUOTWj_Vg4$g==)
    at #=qf_8CePnBDTQrfDWHHp4IV$cZMyjsiL9AKJwRVf52NLmcZQJp8kYTwB2V61ObkaTr.#=qO2eJDTUp8Vd6oe5ORC0Ikw==(Object #=qaGviqTHKzS_BAGmosaSDOQ==)
    at #=qf_8CePnBDTQrfDWHHp4IV$cZMyjsiL9AKJwRVf52NLmcZQJp8kYTwB2V61ObkaTr.#=qF$h_eyldSQMfe2NjI2gK_Q==(Object #=q0ND04lEE8_vIQKXu7dIoRg==)
    at #=qeOe8DSphn2VAklmTYSXzUJSbR8udAGt9Nvg56xORjhiWr3IbSbXWUcxbBxTT09NLYXJLV_x8EIWmrykok7T7RQ==.#=qYNB3No$1AvdOnB58LAd6iYFOIlLffYf3HA7rlBGHWco=.#=qRQZrGFIrMbpmP69ASWPjIA==()
    at #=qeOe8DSphn2VAklmTYSXzUJSbR8udAGt9Nvg56xORjhiWr3IbSbXWUcxbBxTT09NLYXJLV_x8EIWmrykok7T7RQ==.#=qL0yk1OT69qNQ2NmtANn82U1UwzhYyZsp$g49waXQNlc=.#=qhM9ifiCNbSe42uouA8gDrBtNSAE8hCsrdUzoA3nwj4UuO73uUaQrWG0KHAySBPPE()

    my code is here.

    from A in _db.BillDetails_Child
    join B in _db.BillDetails_Main on A.BillID equals B.BillID
    where B.RoomNo == Room_ID
    select new DTOKOTBillDetails
    {
    BillNo =Convert.ToInt32(A.BillNo),
    RoomNo =Convert.ToInt32(B.RoomNo)
    }
  • #749843
    This is because LINQ to Entities does not support Convert.ToInt32, so you have to parse to int outside LINQ not inside Query.

    Please change the Query to below


    var roomList = from A in _db.BillDetails_Child
    join B in _db.BillDetails_Main on A.BillID equals B.BillID
    where B.RoomNo == Room_ID
    select new DTOKOTBillDetails{A.BillNo, B.RoomNo};


    return roomList.ToList()
    .Select(a => a.DTOKOTBillDetails
    {
    BillNo =Convert.ToInt32(A.BillNo),
    RoomNo =Convert.ToInt32(B.RoomNo)
    }



    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #749850
    hi
    i think

    Entities does not recognize the method 'Int32 ToInt32(System.Object)' method

    here your Entity Collection did not find out Integer datatype data or suppose your linq query
    did not match numeric datatype may be that string data type.can u post your Query.

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #749876
    in your below code make some modifications as stated:

    from A in _db.BillDetails_Child
    join B in _db.BillDetails_Main on A.BillID equals B.BillID
    where B.RoomNo == Room_ID
    select new DTOKOTBillDetails
    {
    BillNo =Convert.ToInt32(A.BillNo),
    RoomNo =Convert.ToInt32(B.RoomNo)
    }


    replace above last lines with below code:

    select new DTOKOTBillDetails
    {
    BillNo = A.BillNo.Value,
    RoomNo =(B.RoomNo.Value)
    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #749979
    Thanks to all, to help me.


  • Sign In to post your comments