Geting started with Entity Framework
by Joseph on Apr 21st in ADO Legacy, C#, Entity Framework
So I wrote my first Linq to Entity Framework query today. Took a little bit of research to really understand what was happening, but here goes my explanation:
using (DataBase db = new DataBase()) // Relatively obvious… This sets up the data connection.
{
//var letters = db.Receipt_View; // A custom MSSQL View based on some tables with key info// Next we set up an IQueryable object
// Note that you COULD do this with a ‘var’ object, but since I’m still learning I wanted to do it the ‘hard way’
IQueryablerpQueryable = from e in db.Receipt_View
where e.OrderID == orderID
select e;// Move the selected records into a List for processing
Listrpvi_Receipt_Views = rpQueryable.ToList(); // Pass them to the necessary methods to do their job
CreateAddressBlock(rpvi_Receipt_Views[0]);
CreateGreeting();
HotelBlock();
}
Give it a shot. I’ll never go back to ADO Legacy… Entity Framework all the way!!!