Thursday, August 11, 2011

Back to work on the new My-MSI.net site... well sort of anyway

That's right. I'm back to work on the new My-MSI.net web site... well sort of anyway.

ASP.NET MVC 3 uses LINQ with the EntityFramework and right now I'm trying to figure out how to make the .Last() extension method work the way I kind of need it to work.

Here is the class:

  public class Home
  {
    private Identity MemberId      { getset; }
    private Details  MemberDetails { getset; }
    private BankData BankData      { getset; }
 
    public Home( DbSet<Identity> mi, DbSet<Details> md, DbSet<BankData> bd, long id )
    {
      MemberId = mi.First( m => m.Id == id );
      MemberDetails = md.First( m => m.Id == id );
      BankData = bd.Last();
    }
This class holds the database records for the master page and the opening page of the site.

It may look like we are passing all the records for three tables into the constructor method, but the way the LINQ works is noting is actually retrieved from the database until the first query which is in this constructor method, and even then only the single record we are looking for is returned. So while it looks very inefficient, at runtime it is very efficient!

At runtime the bd.Last() method is throwing an exception that I hope to have resolved sometime tomorrow.

No comments:

Post a Comment