Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Wednesday, 8 December 2010

LINQ: Examples of LINQ to SQL, SQLMetal

Detailed explanation and example for LINQ and SQLMetal.
SQLMetal is a command line tool that allows you to produce your DAL.
http://www.simple-talk.com/dotnet/.net-tools/exploring-linq,-sqlmetal-and-sqltac/

LINQ to SQL and using it for your DAL
http://www.kirupa.com/net/further_exploration_linq_pg1.htm

Tuesday, 7 December 2010

LINQ: LINQPad, Paste XML as XElements

Handy tools for programming in LINQ.
Has cool function to query SQL databases using LINQ!
http://www.linqpad.net/

Scott Hanselman talks about an extension for VS2008 that allows you to paste XML as XElements directly to your source code.
http://www.hanselman.com/blog/PasteXMLAsXLinqXElementVisualStudioAddIn.aspx

LINQ: CSV to XML using LINQ

Code sample from MS to convert CSV to XML using LINQ.


// Create the text file.
string csvString = @"GREAL,Great Lakes Food Market,Howard Snyder,Marketing Manager,(503) 555-7555,2732 Baker Blvd.,Eugene,OR,97403,USA
HUNGC,Hungry Coyote Import Store,Yoshi Latimer,Sales Representative,(503) 555-6874,City Center Plaza 516 Main St.,Elgin,OR,97827,USA
LAZYK,Lazy K Kountry Store,John Steel,Marketing Manager,(509) 555-7969,12 Orchestra Terrace,Walla Walla,WA,99362,USA
LETSS,Let's Stop N Shop,Jaime Yorres,Owner,(415) 555-5938,87 Polk St. Suite 5,San Francisco,CA,94117,USA";
File.WriteAllText("cust.csv", csvString);

// Read into an array of strings.
string[] source = File.ReadAllLines("cust.csv");
XElement cust = new XElement("Root",
    from str in source
    let fields = str.Split(',')
    select new XElement("Customer",
        new XAttribute("CustomerID", fields[0]),
        new XElement("CompanyName", fields[1]),
        new XElement("ContactName", fields[2]),
        new XElement("ContactTitle", fields[3]),
        new XElement("Phone", fields[4]),
        new XElement("FullAddress",
            new XElement("Address", fields[5]),
            new XElement("City", fields[6]),
            new XElement("Region", fields[7]),
            new XElement("PostalCode", fields[8]),
            new XElement("Country", fields[9])
        )
    )
);
Console.WriteLine(cust);


http://msdn.microsoft.com/en-us/library/bb387090(v=VS.90).aspx