none
LINQ syntax RRS feed

  • Question

  • Hi,

    I have three small questions on the use of Linq to SQL :

     

    1. I am filling a gridview this way (french website):

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

    Dim db As New ConcordeDataContext

    'Fill Gridview

    Dim Inscrit_a = From p In db.con_Activ_inscrits _

    Where p.Membre = Profile.Id And p.con_Agenda.Datum >= Today() _

    Order By p.con_Agenda.Datum Descending _

    Select New With {.Date = p.con_Agenda.Datum.Value.ToShortDateString(), .Sujet = p.con_Agenda.Onderwerp, _

    .Heure = p.con_Agenda.Uur, .Pr‚nom = p.con_Membre.Prenom, p.con_Membre.Nom, p.Membre, _

    .Invit‚_nom = p.invite_nom, .Invit‚_pr‚nom = p.invite_prenom, _

    .Orateur = p.con_Agenda.Spreker}

     

    GridView1.DataSource = Inscrit_a

    GridView1.DataBind()

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

    I use an alias to change the title of the columns, like the bold selection in the preceding example.

    How can I make an alias that contains two separate words like :

    .First Name = p.con_Agenda.FName

    Indeed .First Name is not accepted ... nor is .(First Name) .... nor .[First Name] ...

     

     

    2. To concatenate fields in SQL, I use ISNULL(FieldX,' ').

    This prevents concatenated items containing a null not showing.

    Is there a similar expression in LINQ ?

     

     

    3. Where can I find good information on those simple VB LINQ syntax ?

    Most Microsoft books seem to forget about VB.

     

     

    Thank you.

     

     

    Thursday, November 6, 2008 3:57 PM

All replies

  •  

    Hi Caron,

                For your First Question1: Did u tried the same query inside sql whether it shows any error or the query executes fine.If the query works fine in sql then create that as store procedure and call the same inside linq and pass the parameter values.

               Question 2: Here is a small sample of concatenation using linq in VB.

    Dim custQuery = _
        (From c In db.Customers _
        Select c.Phone) _
        .Concat _
        (From c In db.Customers _
        Select c.Fax) _
        .Concat _
        (From e In db.Employees _
        Select e.HomePhone)

    For Each custData In custQuery
        Console.WriteLine(custData)
    Next

           Questions 3: No Info..

     

    Venky

    Friday, November 7, 2008 6:55 AM