Archive for January, 2009

Release of jQuery 1.3

Friday, January 16th, 2009

Welcome to 2009 jQuery!

On January the 14th, 2009 the jQuery team announced the release of the jQuery JavaScript library.

Whats New

What I consider the most important new feature is the new selector engine: Sizzle which is told to improve performance with 50%.

Another new thing is the Live Event which is promised to be an easier way to work with events and even use them again after you’ve used them once.

To check it out yourselves and to see more about these features and many more, go to the jQuery site.

An open-minded Sizzle

What I considered very interesting on the one hand and more than promising on the other hand is the future collaboration with Dojo, Prototype and others to make the Sizzle engine better. This is what I call open-minded!

Backwards Compatibility

If you’ve used jQuery plugins in your projects, before upgrading to jQuery 1.3 be sure that the plugins are up to date.

 

ADO.NET Entity Framework Performance Issues with LINQ to Entities

Friday, January 16th, 2009

Prerequisites

  1. ADO.NET Entity Framework
  2. LINQ to Entities

 

Problem

After you manage to get a feeling of what Entity Framework means you probably begin to wonder “what you I do to make it happen faster”. After a few hours of research, I’ve came to the conclusion that there are some important thins to mention about performance with LINQ to Entities.

Issues

  1. Compiled Linq queries
  2. No Tracking/ Tracking
  3. Lazy Loading: Load()
  4. Early Loading: Include()

Before we begin

We will consider we have the following tables: City with Id, Name, CountryId and Country with Id, Name. So as simple as possible.

     foreach (t1 t in query.Execute(MergeOption.AppendOnly)

References

Compiled Linq queries

public static Func<PerformanceArticleContext, IQueryable<City>>

compiledQuery = CompiledQuery.Compile(

(Context con) =>(from c in con.City select c));

using (PerformanceArticleContext ne = new PerformanceArticleContext())

{

foreach (Orders o in compiledQuery(ne))

{ int i = o.OrderID;}

}

References

Relații în ADO.NET Entity Framework

Monday, January 12th, 2009

Lucrez acum la un proiect în care folosim ASP.NET MVC și ADO.NET Entity Framework. Fiind primul proiect cu EF, descoperim pas cu pas cum anume se lucrează cu el.

Azi m-am lovit de următoarea problemă. Se dau două tabele în baza de date (Întrebare și Categorie), relaționate 1 – *, o categorie corespunzănd la mai multe întrebări, respectiv entitățile generate cu EF. Acesta fiind un Object – Relational Mapper, în clasa Întrebare generată vom avea o proprietate Categorie de tip Categorie, respectiv una CategorieReference de tip EntityReference<Categorie>, fără să avem una de genul IdCategorie.

La un moment dat selectezi câteva Întrebări din entitățile EF, și dorești să vizualizezi Categoria pentru fiecare Întrebare. Ceva de genul acesta:

ViewData["Categorie"] = intrebareSelectata.Categorie;

Vei observa că acest obiect, Categorie, este null. Motivul e simplu: întrebările selectate au fost încărcate din baza de date fără obiectele care rezultă mergând pe relații. Pentru a avea și obiectul Categorie asociat unei Întrebări încărcate, sunt două variante:

1. Atunci când interogăm setul de Întrebări, folosim o metodă care automat include obiectele relaționate:

Intrebare problemaSelectata = (from intrebare in entities.Intrebare.Include("Categorie") …

1. Altfel, fără metoda Include() de mai sus, folosind proprietatea CategorieReference:

problemaSelectata.CategorieReference.Load();

Din acest moment, Categoria aferentă Întrebării (-lor) este și ea încărcată din baza de date.

[UPDATE]

Mi s-a întâmplat (de fapt colegului meu Stefy) ca în unele situații acest eager loading realizat cu metodele Include() să nu meargă. Este explicat mai bine aici: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=347543 , dar pe scurt relatez și eu. Dacă interogarea este ”mai complexă” (nu știu toate cazurile, ei au acolo un exemplu, eu vă arăt altul imediat), atunci Include() pur și simplu nu face nimic. Problema mea e că nici nu aruncă o excepție …

Iată exemplul nostru:

var query = (from intr in entities.Intrebare.Include("Clase")
             join categ in entities.Categorie on intr.Categorie equals categ
             where intr.Formulare.IdFormular == idFormConcurs
                && categ.Domeniu.Id == idDomeniu
             orderby intr.NrOrdine ascending
             select intr).ToList<Intrebare>();

Aici se pare că nu îi place join-ul și acel Include(”Clase”) nu face nimic. Rezolvarea este următoarea:

var query = (from intr in entities.Intrebare.Include("Clase").Include("Categorie")
              where intr.Formulare.IdFormular == idFormConcurs
                  && intr.Categorie.Domeniu.Id == idDomeniu
              orderby intr.NrOrdine ascending
              select intr).ToList<Intrebare>();

Cu alte cuvinte, înlocuim join-ul necesar pentru verificarea unei condiții prin includerea obiectului respectiv folosind Include(”Categorie”) și apoi efectuarea verificării pe obiectul intr.Categorie. E destul de logic până la urmă să lucrăm pe obiecte până la capăt, și nu să avem un mix relațional-obiectual în aceeași interogare.

Views and AggViews

Wednesday, January 7th, 2009

Hey Community Server blog users!

I just started to use my tech blog on CS more often.

Well, while doing this I saw some strange statistics offered by the blog engine.

  • Views

While this one is easy to guess, as being the number of views of the post through browsers (correct me if I’m wrong)…

  • AggViews

…this one is more challenging. After a quick search with “your favorite search engine”[MT] you will find that this statistic counts how many times was this post viewed through RSS and Atom feeds

Enjoy watching them grow ;))

Accessing a Master Page Control from an ASP.NET Child Page

Tuesday, January 6th, 2009

Here you can download the code.

Prerequisites

  • Inheritance  : OOP Concept

First of all, let's be sure we know what a master page is since this is what we are interested in.

I'll resume here only on writing a really really short phrase about it. The Master Page (referred further as Master) is a template for other ASP.NET pages (referred further as Sub Pages).

For more details please read the overview on Master Pages than can be found following the link enlisted in the prerequisites section.

Accessing a Master Page Control from a Child Page

A way to reference a control on a Master Page will be presented below so let's go to the juicy part. There isn't much to say, so I'll put first the problem on the plate. I had some time ago a problem with some controls that were put on the Master page and their values needed to be saved or changed. For that particular time I admit I used a workaround but the solution is simple as accessing a public property of a parent class.

Scenarios

  1. There is a label in the Master. The user of the site gives the correct credentials and hits sign in. We want to change the Text property of the label when we sign in on the site through a SubPage with the name of the user that has just logged in.
  2. Anther possible scenario would be reading the value of a textbox that has just changed in the Master and use it in the SubPage.

Demo

       In this demo we will just make an action(click a button) in the SubPage to change the label in the Master. Above this, I will add a reset button on the Master.

Here is what is needed in the code of the Master:

      public string MyProperty
   {
    set { lblUser.Text = value; }
   }

So a simple public property with a set for the Text property of the required label.
This is what is needed in the Subpage Code, assuming we put a button on the page and treat the OnClick event:

        protected void btnChange_OnClick(object sender, EventArgs e)
   {
    ((MyMaster)this.Master).MyProperty = "Text changed from Sub Page";
   }

We are able to do this because the Master is simply a class that inherits System.Web.UI.MasterPage. And the Label.Text property that we created is just a property of the Master class (this name will be the specific name of your current Master Page, in this case MyMaster). Notice it won't work without a cast to your specific Master Page class and this is because you added a field that does not exist in System.Web.UI.MasterPage the type of  this.Master but in your specific Master Class. To clarify this, I will paste some code

  • the header of the Master class

public partial class MyMaster : System.Web.UI.MasterPage

  • the header of the SubPage class

public partial class SubPage : System.Web.UI.Page

Download

Long story short. Here you can download the code.

More

As I suggested in the second scenario, a getter can be added to the property you want to acces from the SubPage.

Another way to access master page control from content page can be found here.