Open GoogleCodeExporter opened 9 years ago
Retrieving Data as XML from SQL Server
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 10:12
// Create the query
var custs = from c in XElement.Load("Customers.xml").Elements("Customers")
select c ;
// Execute the query
foreach (var customer in custs)
{
Console.WriteLine(customer);
}
//Pause the application
Console.ReadLine();
where c.Element("Country").Value == "Italy"
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 10:24
static void Main(string[] args)
{
WriteRssToDb();
Console.ReadLine();
}
private static void WriteRssToDb()
{
XDocument feed = XDocument.Load("http://weblogs.asp.net/scottgu/rss.aspx");
SampleGayaniDataContext dbContext = new SampleGayaniDataContext();
var feedpost = from post in feed.Descendants("item")
select new RssFeed
{
Tile = post.Element("title").Value,
Date = DateTime.Parse(post.Element("pubDate").Value)
};
dbContext.RssFeeds.InsertAllOnSubmit(feedpost);
dbContext.SubmitChanges();
Console.WriteLine("Successfully inserted, Check your database.");
}
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 10:24
Create the XML Mapping File
<?xml version="1.0" encoding="utf-8" ?>
<Database Name="AdventureWorksLT"
xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">
<Table Name="SalesLT.Customer" Member="Model.Customer">
<Type Name="Model.Customer">
<Column Name="CustomerID" Member="CustomerID" IsDbGenerated="true" IsPrimaryKey="true" />
<Column Name="Title" Member="Title" />
<Column Name="FirstName" Member="FirstName" />
<Column Name="LastName" Member="LastName" />
<Column Name="ModifiedDate" Member="ModifiedDate" />
</Type>
</Table>
<Function Name="dbo.ap_GetCustomerByLastName" Method="GetCustomerByLastName">
<Parameter Name="lastNameLetter" Parameter="LastNameLetter" />
<ElementType Name="Model.Customer" />
</Function>
</Database>
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 10:31
<?xml version="1.0" encoding="UTF-8"?>
<tables>
<table name="Author">
<field name="first" type="text"/>
<field name="last" type="text"/>
</table>
<table name="Publisher">
<field name="name" type="text"/>
<field name="last" type="text"/>
</table>
<table name="Book">
<field name="name" type="text"/>
<field name="author" type="id"/>
<field name="publisher" type="id"/>
</table>
</tables>
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 11:42
这段简单的 XML
脚本定义了三个数据库表及其字段:Author(作者)、Publisher��
�出版商)和 Book(图书)。
Original comment by cn.wei.hp@gmail.com
on 7 Dec 2010 at 11:43
Original issue reported on code.google.com by
cn.wei.hp@gmail.com
on 7 Dec 2010 at 9:48