none
Error to Calling User Defined Function in Linq RRS feed

  • Question

  • I've createda function calledcompcode , but when i calling it from linq Command , i get Error (below Picture)

    help please

     Dim cl As New Class1
    
            Dim db As New WebDatabaseEntities
            Dim query = From l In db.ListMonHed
                        Join k In db.KarSpec
                        On l.KarId Equals k.id
                        Where l.KarId = k.id And l.Userid = userid
                        Order By l.id Descending
                        Select New With {Key .id = l.id, .fullname = k.KarName + " - " + k.KarNo, .pymno = l.PymNo,
                                           .Dore = cl.compCode(l.Year.ToString, 4) + "-" + cl.compCode(l.Month.ToString, 2), .listno = l.ListNo}
    
            With GridView1
                .DataSource = query.ToList
                .DataBind()
            End With

    Wednesday, September 30, 2015 9:35 AM

All replies

  • The problem is that you are trying to get SQL Server to execute code on your PC.  There is a class cl (class1) which you want to use to in the executing statement.  This won't work.

    What you will need to do is execute the statement and then massage the returned data in a second statement.


    Lloyd Sheen

    Wednesday, September 30, 2015 10:16 PM
  • in the Table ,values of year & Month are stored in integer datatype.

    I want to show year and month value to gridview with this format   (2015-02)

    if length of year value less than 4 digit (for example: 890) , compcode function returned (0890)

    and if length of month value less than 2 digit (for example : 2) , compcode function returned (02)

    So In the above example instead of (8902)  , i want show it to  this format (0890-02).

    And as for the rest of the values :

    2015-02

    2014-12

    1995-03

    0980-12

    ....


    • Edited by Ashkan209 Thursday, October 1, 2015 3:55 AM
    Thursday, October 1, 2015 3:55 AM
  • You will need to either change your database design to store dates as dates or retrieve the stored data in its current format and reformat at the workstation not through Linq.

    Lloyd Sheen

    Thursday, October 1, 2015 3:29 PM