Interview Questions Headline Animator

Monday, April 28, 2008

If Microsoft Goes Hostile on Yahoo... Amazing Read...

http://blog.pmarca.com/2008/04/if-microsoft-go.html

Joins in LINQ... What do I return?

I want to write a select query that returns all the data in a table? this is how it would go:

IQueryable<Session> sessions = from session in dataContext.Sessions

where (session.EventID.Equals(eventID))

select session;

Now I want to write a select query that joins two tables. This is how it would go:

var x = from s in dataContext.Sessions

from e in dataContext.Events

select new

{

s.SessionName,

s.SessionDescription,

e.EventName

};

So this is the easy part. we just learnt how to write the query. Now consider this. I have a separate data access layer that does all the basic query generation and works as a data interface. I generate the first query here and then in my engine or the middle tier, I refine my query depending on what the UI layer requires. So in a situation like that I have a function in my Data Access Layer that does a table join... what would this function return. I can't return IQueryable<Session> or whatever is the Table Name because I am making a join and so it is no specific table. I am supposed to be returning an anonymous class. How do I return an Anonymous Class from a function. The whole idea of the anonymous class is that the class name is anonymous. So this is what I do.

public object GetSessionAndEventData()

{

if (string.IsNullOrEmpty(this.connectionString))

{

this.connectionString = ConfigurationManager.ConnectionStrings[MADConstants.CONNECTIONSTRING].ToString();

}

if (this.dataContext == null)

{

this.dataContext = new EntitiesDataContext(this.connectionString);

}

var x = from s in dataContext.Sessions

from e in dataContext.Events

select new

{

s.SessionName,

s.SessionDescription,

e.EventName

};

return x;

}

Yes. I just return an object. While I was thinking about this, I did some reading and discovered something quite interesting in the C# 3.0 specification. "Within the same program, two anonymous object initializers, that specify a same sequence of properties of the same names and types, in the same order, will produce the instance of the same anonymous type". The compiler uses the same generated class if there are two object initializers of the same type. This actually makes it possible to cast it back to the original type.

Then what I did was, I just returned an object type from my data access layer, passed it through the middle tier engine, and all the way to UI. here I just bound my datagrid with the object type and voila...! The Datagrid was actually able to bring out the properties and put them in tabular format without requiring any casting.

Don't you just love it when it just works...!

Update on future plans on my career... Just a reminder...

So what do you feel like when you first board the mother ship. Death...! yeah... for someone who has been growing and dreaming and aiming high all his life (only such a person usually boards the mother ship)... where do you go once you join Microsoft...

There are goals like achieving targets, promotions, accolades; growing the ladder... But is that it...? Does life have nothing that big left...? Big enough like the ambition of joining Microsoft...? This is what I went through the first 3 months of my career...

I had to come up with something... So I did... A lot of people had been telling me that I write good... Specially my girl... who happens to be a huge inspiration... So I decided I would write a book... after a lot of thought and pondering... I decided  I would write something on Engineering Excellence... A subject that never goes out of scope. Number of reasons why I decided that... Since this is my first book it would take a lot of time... to even start it... Anyways coming back... spent 5 more months in all this pondering... and I still haven't written a single word or done nothing towards writing... Hell I am too stuck with my stretch initiatives at work and my mundane responsibilities...

So I decided I would start the book in December. Till then I will prepare. Build a monster machine that I have been planning for some time, read, read, read and read...

And then it happened. Ray Ozzie came to Hyderabad Campus... Short talk he gave and I got my next big thing. Joining the Microsoft India Development Center (IDC), which happens to be the products division in India. I will start preparing today itself and it is a one year target... I should be in IDC before 2009 December... I am giving myself enough time because I have to get married somewhere towards the end of 2008, and a honeymoon follows, and then the initial distractions of marriage and setting up a house and so on and so forth.

I also have to work on the monster machine, the book... although working on the book pretty much goes hand in hand with preparing myself for IDC... But still... I am sure IDC would require something more than just Engineering Excellence.

Wednesday, April 09, 2008

Command Copy exited with Code 1

If you get that error message, it is usually because you have configured your application to run some batch copy commands either just before the build of the app or after it. So go to Project Properties -> Build Events and check if there are any pre-build events or post-build events with any copy command. This usually happens when you get a version of legacy code that some other developer has written and are working on some fixes.

First check if there are any discrepancies with the copy command syntax or the directory path mentioned therein. If you can't resolve the error because of constraints such as not being able to change the directory structure, just get rid of the commands for the time-being and continue with your dev. You can later on figure out what the original intent of the previous developer was and go for the solution.

Tuesday, April 08, 2008

login failed for user (Microsoft SQL Server error: 18456)

So you had some problems with your installation of the SQL Server 2005 installation on your machine and now that you have un-installed and installed it, you can't seem to log on to your own machine using basic windows authentication. You can log into other servers but you just can't seem to log on to localhost. So you search the internet for the error message and after going through a whole lot of issues that are vaguely related, like changing authentication type from windows to sql and so on and so forth, you land on my blog.

The Solution: Install Visual Studio 2005 SP2

This was a bug in SQL Server 2005 that was fixed in SP2.