RSS

Monthly Archives: March 2011

How to Learn New Technology (as in Language / Framework / Tools)

  1. Watch videos (google it!).
  2. Read white paper (to understand the architecture).
  3. Buy, or borrow, and read the books.
  4. Attend the user groups.
  5. Use it! – create use cases and apply your learning.
  6. Write about it.

Updates are coming…

Advertisements
 
Leave a comment

Posted by on March 24, 2011 in General

 

Tags: ,

Troubleshooting Principles

  1. Understand the system workflow.
  2. Learn the basic design (pattern).
  3. Read the error message thoroughly.

Updates are coming…

 
Leave a comment

Posted by on March 24, 2011 in General

 

Tags: ,

Getting to Know James Altucher

I came across this guy named James Altucher today. Apparently, he was a programmer in his early career life. Now, he is a stock trader, entrepreneur, writer and fund manager. Heck, he even plays chess and won a tournament!

Spending few minutes on his blogs I quickly find that most people disagree with his perspective. But, all I have to say about this guy is, he is truly inspiring! Straight forward in his writing (to which I mostly agree) and he always stand on his own principles. And no, I am not one of his relatives nor did I relate to him in anyway. So writing this post about him will not cause Claudia-incident.

I am personally inspired with his idea of writing down any ideas about problems, better-living, anything. Most of these ideas will NOT work, trust me. But, that’s not the point. The point is to stimulate our thinking and ability to generate more ideas, better ideas. The hardest part is to come out with first few ideas, after that, it flows like waterfall. Bottom line is, to exercise the brain and practice problem solving. It’s true when they said we only use 7% (not-so-accurate-number, but you get the idea) of our brain.

Having said that, I just want ping him back in my blog as form of my support.

Here’s some of his articles I read:
10 more reasons why parents should not send their kids to college
8 alternatives to college
how to be the luckiest guy on the planet in 4 easy steps
what it feels like to be rich

ps: one thing I notice though, his first blog post was in feb 2001. But he didn’t post anything until feb 2010. weird, huh?

 
Leave a comment

Posted by on March 24, 2011 in General

 

Tags:

Use ViewModel (Model Binder) in LINQ to Entity Framework – LINQ Doesn’t Return All Joined Data

When using Entity Framework, I’ve found that the join LINQ query that I specified will not return all the data I needed.

Although the query includes OpmaDB.Property entity, the entity is not included in the result object. So, statement like:

_propertyList.FirstOrDefault().Property.PropertyId

will return the famous-‘Object reference not set to an object of an instance’-error:

To resolve this issue, we can use ViewModel, or Model Binder, instead of the entity itself. This should be the better practice anyway. The query looks like:

And the ViewModel looks like this:

Alternatively, we can also store the whole entity model in the View Model instead of property members of the entity. This is how I would do it, the ViewModel:

And the query:

 
Leave a comment

Posted by on March 21, 2011 in General

 

Tags: , , , ,

Select Many to Many Relationship in LINQ to Entity Framework

Linq to Entity Framework query looks little bit different when it comes to selecting database records from two tables in which the relationship is many-to-many.

The database diagram looks like:

In regular T-SQL query, I would normally do this:

SELECT Departments.*, Rooms.*
FROM Departments INNER JOIN DepartmentRoomJunction ON Departments.Id = DepartmentRoomJunction.DepartmentId
	INNER JOIN Rooms ON DepartmentRoomJunction.RoomId = Rooms.Id
	WHERE Departments.Id = 2

The result is:

However, when try to do ‘join’ in Linq, the Intellisense doesn’t show Entity object that I want.

Linq is little bit different when it comes to querying many-to-many relationship. Here’s the code:

var _departments = from d in _context.Departments
                           from r in _context.Rooms
                           where d.Id == 2
                           select d;

This is because in Entity Framework, many-to-many relationship are automatically joined. So, there is no need to join them again in the query. As you can see the Entity data model designer below, both Departments and Rooms are not connected with a junction table, as it would with the database diagram.

 
Leave a comment

Posted by on March 21, 2011 in General

 

Tags: , , , ,

What is Dependency Injection?

Martin Fowler original coined the term in his article, “Inversion of Control Containers and the Dependency Injection pattern”. In it, he explains in great details his approach in creating high cohesive application with weak coupling modules. It’s a design pattern that allows a separate assembler module to inject the implementation into a class. The author derived Dependency Injection from Inversion of Controller for a more specific name for this pattern.

In my simple definition, dependency injection is a concept to move dependency between classes / controls / methods / interfaces by place this dependency in a configuration files (such as xml-based config file).

Before the dependency injection time, developers achieve weak coupling by manually injected dependency in a new class. This new class is responsible for bridging the other two classes. This approach introduces new problem such as, when modifications need to be done in the code, the code will need to be recompiled.

Scott Hanselman has a good list of .Net Containers that can be found here.

Another good read for Dependency Injection term is from Wikipedia.

 
Leave a comment

Posted by on March 21, 2011 in General

 

Tags: , , ,

Select First and Second Highest Record in Database

The table is:

So far, I’ve found two ways to do this

TOP()

SELECT TOP(1) *
FROM (SELECT TOP(2) *
    FROM Salary
    ORDER BY Amount DESC) AS TOP2
ORDER BY Amount

MAX()

SELECT MAX(Amount)
FROM Salary
WHERE Amount Not In (SELECT MAX(Amount) FROM Salary)

I personally like the “TOP()” approach just because of its flexibility. If I want to select third, fourth, or fifth highest record, all I need to do is change the number in the second TOP() statement.

 
Leave a comment

Posted by on March 21, 2011 in General

 

Tags:

 
%d bloggers like this: