Share on Twitter

Recently I started working on some interesting HTML 5, CSS 3 and JavaScript bits (involving jQuery and jQuery UI). I have worked with all of them before, but not as extensively. Most of my work is some reusable stuff that I can develop generic demos out of (from scratch, unrelated to the custom stuff required here), however, the size of each made me always lazy to take the opportunity to share some nice stuff with you via GuruStop.

I decided to encourage myself to stop laziness by sharing a very small part, then hopefully follow with the real interesting stuff.  Today we look at a simple String.Format() function, similar to the one available in .NET / C#, meaning it uses {0}, {1}, etc… as placeholders.

Look at the code, click the “HTML” tab for the sample HTML used for this one(just a div with an ID), and “Result” for trying it out yourself.  You can also click the “+” button at the right and edit it if you like to!

Note that this one is intended for simple scenarios only. If you need complex / flexible templates, use some templates library like JsRender or knouckOutJS templates.

, ,
Share on Twitter

This one is a Back-To-Basics style post. Last month, I was checking some code for the relatively new .NET open source blog engine, FunnelWeb, and noticed this bit of code:

funnelwebsrcFunnelWeb.Extensions.CommentNotificationCommentPostedListener.cs

ThreadPool.QueueUserWorkItem(

    delegate

        {

            SendEmail(settings, commentDetails);

        });

 

This is just a real easy way to make async call, right?

 

BTW, you can learn more about the ThreadPool.QueueUserWorkItem() method from MSDN here.

 

More Interesting Stuff

Playing with it after reading, I found that Matt Valerio seems to have very interesting takes on this method, making you use it in many elegant ways:

 

I highly recommend the first two articles especially, the code is really elegant.

 

What IS This Post???

I felt a strong desire to blog something before I go to work today and wanted to see if that’s possible.

Not sure if I should write more posts like this, or am I then converting the blog here to a micro-blog/twitter/tumblr of some kind.

,
Share on Twitter

In NHibernate there is a Save(entityObject) method, which creates a new row in the database with the given entity object, also, has an Update(entityObject) which updates the row corresponding to the entity object with the property values of this object. It also has a SaveOrUpdate(entityObject) method, which checks the whether the entity object corresponds to an existing row in the database, and chooses whether to call Save(…) or Update(…) based on that.

The way I usually do web applications across multiple tiers, when not using view models specifically, makes me encapsulate much code in Services layer that sometimes does not need to care about whether the given entity is persisted in database or not. Thus wanted to have similar method using Entity Framework as ORM.

Of course I have implemented the method number of times and the code evolved based on which version of Entity Framework I’m coding against, and my knowledge of the framework internals as well.  Actually, when you work with so many ORMs like I did, a new ORM or ORM version turns to only sound like “What’s new in the manual?” thing.

, , , , , ,
Share on Twitter

If you don’t know what eager loading is, Jump to “What’s eager loading?”.

Eager Loading Syntax

If you are eager loading Products for example in a typical (Categories 1<->* Products) relation, the standard syntax would like:

DbDataContext.Categories.Include(“Products”)

What is the problem with that?

The “Products” part. The word “Products” is a string. If I rename the Products table to ShopProducts or whatever or even remove it from this data diagram and have it elsewhere, or even something wrong happens and the relation is removed from DB/diagram by mistake, my code will still compile, but will fail when it runs. This is BAD BAD BAD.

How to solve this?

Since I always believe that if something exists somewhere you shouldn’t do it yourself unless its totally broken (and I mean REALLY REALLY BROKEN), I started searching inside the Entity Framework itself for something to get the entity name from.

At first it seemed super easy. Every entity class has a static property “EntityKeyPropertyName”, so, I thought I can write something like:

DbDataContext.Categories.Include(Product.EntityKeyPropertyName); // But this didn’t work

, , , , ,
Share on Twitter

Slideshare is quickly becoming the defacto standard for sharing presentation slides, just as YouTube for videos, and Flickr for images. I recently got into the habit to share my presentations there and use the embed feature to include it in my weblog, and this was the same for the "Design Patterns Via C# 3.0" session.

This morning I got this email from SlideShare

Hey Mohamed_Meligy!
Your slideshow
Design Patterns Via C# 3.0 has been featured on the SlideShare homepage by our editorial team.
Cheers,
- the SlideShare team

WOW .. I couldn’t believe it until I went to SlideShare.net and saw it myself …

Featured Homepage

 

Thank you SlideShare. I never expected the slides to be interesting to that extent :D :D :D.

Share on Twitter
, , ,