getting there

by Dave Thu 31 January 2008 @ 02:18

So I wrote most of the display engine for the new blog system last night and today.  Visually it looks exactly as it did before, but the technology behind it is different.  I am now faced with an interesting decision though.  I have the new engine written in LINQ as I said in the previous post, but I'm wondering if this is the most efficient way of doing it.  I have no idea of the memory and processor footprint of LINQ, nor do I know how its performance compares against ADO.Net.  These are things that'll have to be figured out soon enough I guess.  So, on to the code :

In the previous post you saw that I used a LINQ expression to query the data from the SQL Server.  At the end of that code I kept the connection.  Its used now to get the contents of the blog as below.  Again, it is terribly easy stuff, no real thought required (except for syntax as writing C# from scratch is new to me).

   1: // Get the data from the database using LINQ
   2: var topTen =
   3:     (from bl in lpcsql.Blogs
   4:      where bl.PostType == 1
   5:      orderby bl.ID descending
   6:      select bl).Take(10);
   7: // Bind data to the repeater.
   8: objBlog.DataSource = topTen;
   9: objBlog.DataBind();
  10: // Check if its me, and if so activate the Edit and Delete controls
  11: if (User.IsInRole("Administrators"))
  12:     {
  13:     for (int post=0; post < objBlog.Items.Count; post++)
  14:         {
  15:             Label lbl = (Label)objBlog.Items[post].FindControl("EditControl");
  16:             if (lbl.Visible == false)
  17:                 lbl.Visible = true;
  18:             if (lbl.Enabled == false)
  19:                 lbl.Enabled=true;
  20:         }
  21:     }
  22: lpcsql.Connection.Close();

And that's the bulk of the LPC display engine.  If you can see a better / more efficient / cleaner way of doing it then please let me know.  I'm new to this language :-)

Categorised : Programming
Tagged with : , ,


Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Johann Sebastian Bach's grave is here, along with the organ whose construction he advised on. Pretty awesome tbh :-)This is where US and Soviet forces met for the first time in world war two.Awesome awesome view from a restaurant on top of the Bastei!We had lunch in Meissen at the cafe in the famous porcelain factory, and ate from about €1000 worth of chinaA little light lunch and some wine...Dresden's famous frauenkirche, recently rebuilt after being destroyed in the second world war.