ADO.NET Mapping API
Hello,
I've recently looked ADO.NET vNext CTP and have one question.
At the following code we use ordinary classes and methods like we use at connections, commands and datareaders.
Are they inherits from these classes or maybe it's some new API but similat to previous? Is it necessary to learn new classes and methods?
using(MapConnection con = new MapConnection(CONNECTION_STRING)) {
con.Open();
MapCommand cmd = new MapCommand(
"SELECT c.CategoryName, c.Description FROM NorthwindLib.Northwind.Categories AS c ORDER BY c.CategoryName",
con);
// Map command requires SequentialAccess
DbDataReader r = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
while(r.Read()) {
Console.WriteLine("{0}\t{1}", r[0], r[1]);
}
}
Thanks
[807 byte] By [
MiXen] at [2008-2-23]
At a minimum there are a few new classes you need to learn about in order to program with entities. For example, in your code you're using a MapConnection and a MapCommand to connect to your entity model and execute a query. From there you get back a reader which is the same code you would write with ADO.NET 2.0. Although MapConnection and MapCommand are new classes, they follow the same provider model that exists in ADO.NET 2.0.
Of course, you can also program against entities as objects, in which case the new API that you learn is the object API around your own data.
Sections 3 and 4 of the overview document that comes with the CTP detail the progression from using the MapConnection and MapCommand with Entity SQL to using LINQ to Entities to return objects. Here's an example from the document.
using(AdventureWorksDB aw =newAdventureWorksDB(Settings.Default.AdventureWorks)) {
var newSalesPeople =from pin aw.SalesPeople
where p.HireDate > hireDate
orderby p.HireDate, p.FirstName
selectnew { Name = p.FirstName + " " + p.LastName,
HireDate = p.HireDate };
foreach(SalesPerson pin newSalesPeople) {
Console.WriteLine("{0}\t{1}", p.FirstName, p.LastName);
}
}
-Lance