Wednesday, May 18, 2011

what is context.createquery method in LINQ




using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts
            AS contact WHERE contact.FirstName = @fn"
;

    ObjectQuery<Contact> contactQuery =
        context.CreateQuery<Contact>(queryString,
            new ObjectParameter("fn", "Frances"));

    // Iterate through the collection of Contact items.
    foreach (Contact result in contactQuery)
        Console.WriteLine("First Name: {0}, Last Name: {1}",
        result.FirstName, result.LastName);
}

No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...