I know this probably sounds like a crazy exercise, but I've been finding it very enlightening.
I've been working on the one application for about 12 months (personal project). I know exactly what I want to do with it, but because I've been exploring a stack of new technologies, I'm finiding that I'll get part of the functionality working, and then rewrite the code in a new technology stack. I've played with Rest, MVC, ADO.NET, Linq, Entity Framework, WinForms and a host of other bits. WPF is on the list to investigate once I get the functionality running the way that I want.
One nice thing about this 'playing around' is that I know the logic, the general structure, and the high level architecture. As I go along, I'm finding my code is more precise... less verbose. I hate giving out my code when I'm 'tinkering' ... it always looks like a dogs breakfast. But by the time I'm finished, it's generally pretty much to the point and clean. I remember a bug I worked on at work a few years ago, the initial code was lines and lines long. I spent about a week on it. And the end result was about 3 lines long.
Kind of makes me think that code would be so much nicer if you got to rewrite a major system after you initially built it. It probably would be more stable, more efficient, and easier to maintain.
I think this is why some artists get stuck on the same subject matter, repainting using new tools, techniques and methods. It's all about editting, revising and rethinking. I'm getting to the point now where I just want to finish to application so I can actually start using it.
Sunday, December 13, 2009
Saturday, December 12, 2009
Entity Framework query
Three examples of doing a simple select operation - one using standard entity framework, one using Linq to Entities, one using a lambda expression.
//example using entities. No filtering of the data.
var books = context.Book;foreach (var book in books)
{
Console.WriteLine("{0} {1} {2}", book.Author, book.Title, book.URL);
}
//example using Linq to entities. Adding in a where clause to filter out the data a bit
var booksLinq = from b in context.Book
where b.Author.Contains("Brown")
select b;
foreach (var item in booksLinq)
{
Console.WriteLine("{0} {1} {2}", item.Author, item.Title, item.URL);
}
//example using lambda
var booksLambda = context.Book.Where(c => c.Author.Contains("Brown"));foreach (var book in booksLambda )
{
Console.WriteLine("{0} {1} {2}", book.Author, book.Title, book.URL);
}
Subscribe to:
Posts (Atom)
