Interview Questions Headline Animator

Tuesday, December 29, 2009

Joomla… or should it be Zoomla…

I have been thinking of owning a website of my own for a long time. First web space was expensive. Not universally, but at least for me. Always thought, is it worth it? How am I justify the annual cost no matter how little. And then of course my salary wasn’t that big then.

Well by God’s grace I am doing pretty ok now. But since the last couple of years, I just didn’t have the time to do it.

I bought web space some 1 and a half year back. wrote a whiz bang application that would host a video invitation to my marriage. Yeah we wanted it to be different, so we made a video wedding invitation.

Anyways. I own a web space since then and I never had the time to create a portal out of it. Just the default page. And then one day I decided to go to godaddy.com and check out what my money buys me. And it turns out that it is more than just the space. I get a host of other products free with it. like Blogs, Emails, CMS, etc.

Honestly, I felt a little shy using the CMS initially. I being a developer should be able to write my own asp.Net application. I bought the damn windows hosting with .Net and everything. I should use it. But then I figured that having a CMS made website is better than not having one. Joomla is what I ended up using.

Usually I ramble about Microsoft Technologies here. But I have to tell you guys. joomla really is zoomla. Initially it might look confusing. But once you get a hang of it, you will have your website ready pronto.

I have mine ready in 1 day. It is called http://www.dasboard.in. It is not much. Not that I have built the next google or anything. But its something, and its there. All that waiting and all it takes is a day.

Wednesday, October 28, 2009

What’s it about a phone that pulls you so hard…??

So I have a Sony Ericsson P990i. So what…? So what if I had a P910i before this and a P900 before that…? So what…? Why did i feel so much attracted to the Experia X1 and why do I feel an even harder pull towards the Experia X2.




I guess men are going to be men… And they will get attracted to unachievably expensive gadgets no matter what…

Tuesday, September 22, 2009

Visual Studio 2008 Unit tests… Error loading *.vsmdi: *.vsmdi

I got this error. I got no information on the internet as to how to get around it…

3 hours earlier:

I wanted to create a sequence diagram from the code I have already written. Visual Studio 2010 comes with the sequence diagram feature. I decided heck why not use it. It creates some really cool sequence diagrams. I opened the same project in Visual Studio 2010, created the sequence diagram, closed the project. Went for a smoke.

30 minutes earlier:

My test cases won’t run. the error I get is  “Error loading xxx.vsmdi: D:\Projects\xxx\xxx.vsmdi” looked here, looked there looked everywhere. But didn’t look in the place I should have been looking.

10 minutes earlier:

I built the test project. I got an error. “Project file contains ToolsVersion="4.0", which is not supported by this version of MSBuild. Treating the project as if it had ToolsVersion="3.5".”

Well I should have been looking at this 30 minutes ago. I went to the test projects Properties, went to TargetFramework and checked. it was not selected at all. I selected Framework 3.5.

After this all I had to do was close the project and open it and then run all my tests in the solution.

They were all still green. Love it when that happens…!!

Tuesday, September 08, 2009

UML 101

So you need to read the entire UML book in 20 minutes. What do you do? These are the excerpts from the Unified Modeling Language Reference Manual I was reading and thought I could summarize for a quick refresh.

 

clip_image002

Aggregation and composition:

clip_image004

Generalization:

clip_image006

Kinds of dependencies:

clip_image008

clip_image010

Use case diagram:

clip_image012

Kinds of Use Case relationships:

clip_image014

clip_image016

clip_image018

clip_image020

clip_image022

clip_image024

clip_image026

clip_image028

Activity Diagram:

clip_image030

clip_image032

Sequence diagrams and Activation:

clip_image034

clip_image036

clip_image038

Component Diagram:

clip_image040

Deployment Diagram:

clip_image042

Packages and relationships:

clip_image044

Saturday, August 22, 2009

Dots instead of spaces in Studio 2008 while running test cases…

Well I was running my test cases today and suddenly all my white spaces turned into dots. Yes it creeped the heck out of me.

First thing I thought was to get rid of that. Went to Tools and Options and couldn’t find the setting that would get rid of the nauseating dots.

So I started trying all the shortcut keys. But initially nothing worked. Now Ctrl + R + D happens to be a combination that debugs the tests in context. So I thought the key pattern that enables and disables the visible whitespace feature has to be similar.

Discovery: Ctrl + E + S

Tuesday, August 18, 2009

Left outer join in Entity Framework

This evening I heard someone say that Left Outer Joins are not possible in Entity Framework or perhaps Left Outer Joins are possible, but they bring in all the data and then filter out the right table.

I felt an urge to argue, but I resisted. I thought I would investigate before I waste time. I came up with some articles pretty quickly.

  1. Left Outer Join in LINQ
  2. Left Outer Join using Inverse Navigation Property
  3. DefiningQuery Element
  4. Left Outer Join in LINQ to SQL
  5. LINQ to Entities with Multiple Left Outer Joins

I am sure these should resolve all questions related to Left Outer Joins.

Now about the performance and the question about how the data is brought, I am pretty sure we can prove that LINQ Queries all support deferred execution. But we can always prove that using the SQL Query Profiler.

Hope this helps.

Wednesday, July 29, 2009

Singleton Vs. Static Class

Well I was asked this question once. “What is a singleton design pattern and why should I use it? Why not use a static class instead?”

And it was quite surprising how it went. I said that Singleton is used when you need to maintain state. Static classes are used when you want to club together a bunch of stateless methods that do something irrespective of which instance calls these methods. Math class is a good example.

So he asked me, can I not maintain state in a static class? So I said if you want to instantiate something in a static class how would imageyou do it? And surprisingly he told me that he would do it in a static constructor. I asked him, is it possible to instantiate anything in the static constructor or even declare an instance type in a static class? And he asked me is it not possible? I said it is not as far as I know and he asked me if I am sure.

Now the way the questions were asked about this subject, I was quite surprised. The interviewer looked quite convinced that instance types can be declared in a static class. I am surprised how he was allowed to take the interview in the first place. Or was he checking my confidence?

I wonder.

Monday, July 27, 2009

To query the local object context

When faced with the dilemma that what if I wanted to insert something and before I actually saved the changes into a persistent storage (database) by calling SaveAllChanges() method on the data context, I wanted to do a select, and also I wanted to make sure that this select is done on the just inserted objects, what should I be doing?

Well generally we write a generic method that gets all the records for a generic object. it looks like this:

IQueryable<T> result = null;

string type = typeof(T).Name;

//ObjectQuery query = entities.CreateQuery<T>(type);

ObjectQuery query = Context.CreateQuery<T>(type);

result = (

IQueryable<T>)query;

return result;

This will only query into the database. So if you have just recently inserted some records, but haven't yet committed them, they won’t appear in the results.

However, if we provide another method (an overload perhaps) that handles local objects, this would be possible. When I say local objects, I mean objects that have been inserted into the Object Context and yet not been persisted into the database. this method would look something like this:

IQueryable

<T> result = null;

string type = typeof(T).Name;

return from stateEntry in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added |

EntityState.Modified |

EntityState.Unchanged)

where stateEntry.Entity != null && stateEntry.EntitySet.Name == type

select stateEntry.Entity as T;

This way we give the option to the user of the API to choose which kind of select he wants to fire. A local one or one on the database.

Tuesday, July 14, 2009

Entity Framework, Business Objects and Beyond…

Back during the RMI days, we used to generate skeleton (henceforth referred to as skel or skels) and stubs for all long range service communications… Yes… WCF has its roots there and perhaps further into the past…! Details available here.

Looking at it from an architectural perspective, the data contracts were designed in such a way that the changes are minimal because every change in the stub would have to trickle down all the way to the client.

We have come a long now and Service Oriented Architecture is something that must be considered in any well behaved and decent enterprise application. In an environment such as this, I wouldn’t ever suggest having client dependencies on any 7 letter word starting with an ‘s’ ending with an ‘e’ and having ‘ervic’ in between.

We should think about providing all client apps independence so that any server / database / service changes do not affect the client… to a great extent…

Now there is a big discussion going on across the Internet about whether business objects should be separately created or should we treat EF entities as business objects. After all that’s what they are. Business Objects carry data from the client to the server and back and that’s what EF entities do… really really well… with all those amazing features such as state management, change tracking, yadda yadda… “straight out of the box” as they call it…

“Well couldn’t I agree more. But wait… entities are created from the database right…? using the EF Designer…?”

“Yes… and you could create in a number of other ways…”

“Well… doesn’t that mean that the design of my business objects would be dictated by the database design?”

“Of course not… Hell no… it is not necessary that you have to import all the entities from the database straight… of course you have the choice to customize them… manually…”

“Hmm… That’s nice… so now I can create my business objects with inheritance and everything just as I want them to and then map it to my database… True Object Relational Mapping…”

“Umm… Wait… did you say Inheritance… well you have that exception… you see the entities are already inherited from ObjectContext. And since there is no true multiple inheritance… you have that constraint… At least not in Framework 3.5… I don’t know if that would be available in Framework 4.0 either…”

“Ok… so what if the structure of the entities change…”

“Well all you have to do is regenerate the proxies and you are done…”

“Umm… new proxies…? Do you mean a change in the data contract…? what if I am not consuming the change… Like I have first name and last name in one of my screen and I don’t need the middle name although, i need it somewhere in the server… Do I still have to break the data contract…?”

“Err… Yes…”

Precisely why you should not be using Custom Entities or EF entities as business objects. You might be able to solve all your problems using partial classes and all code customizations… But end of the day, you are breaking the dependency rule.

There’s a reason why they call it a Data Contract.

The solution would be to create a separate business objects layer and then map your business objects with the EF entities. There are a couple of really smart implementations available. One of them could be implementing the Observer Design Pattern so any change could be tracked and reacted to.

Speaking of which I just discovered a good video in which Eric Meijer talks about the Reactive Framework. Definitely worth a watch.

Tuesday, July 07, 2009

“Open in new tab” hangs IE 8

I have been facing this problem for some time, and to tell you the truth, it gets a little embarrassing when if you are trying to show something to a larger group.

All you need to do these days, is Bing it and I got this. But this is with IE 8. Heck I thought why not give it a shot. And what do you know. It works with IE 8 too.

Wednesday, June 03, 2009

Function Import and loading of referenced data

Why do Entity Framework Function Imports do not have eager loading? Because when you use Entity SQL or regular Object context to retrieve data, it is a live connection. So whenever you say eager loading enabled, it gets the data from the database using the live connection. But if you want to do it using Function Import, EF doesn’t know where to get the data from, since the stored procedure that the function import maps to, doesn’t get that data. Perhaps in the later versions of EF, the team might add the feature which can mix and match the object context and the stored procedure to get the required data. But as of now it is not possible.

Saturday, May 30, 2009

Does not have a valid user

“Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects”

You are sitting at home, working on your work laptop, you have a deadline to meet, give an entity relationship diagram for your technical specification document for the module you are working on. So you decide to create a temporary database on your machine itself and then generate a database diagram.

You try to create the diagram and this is the error message you get. You go check the “Files” page of the database properties and it rightly contains your office alias. you refresh it and it still doesn’t work. You think it is some security / privilege issue. You check the Securities tab and everything is in order. It still doesn’t work.

You distinctly remember it to be working when you tried it yesterday at work. It just doesn’t budge now. Wonder what’s wrong.

The problem is you were at work yesterday which you are not now. Meaning you are not on the corporate network and you don’t have the Domain Server available. SQL Server tries to validate your credentials with the Domain Server. It doesn’t find it. If you have any means to get on to your corporate network, like RAS, perhaps, then you should and you will see it will work like magic.

Thursday, May 28, 2009

Xsd to Database

There are times when you have to work with XML. Yes those dreadful times. Specially the times when you get data as XML. And not just master data you sometimes get transactional data in XML. Think about it. How much worse can it get if you had to work with transactional data, and sync it with the database?

I am working on something in that direction. Although I haven’t finalized the approach yet, but it would involve creating an xsd, converting the xsd into datasets and then moving the data into the database.

But have you wondered how you would create a database that is similar to the xsd? Of course you won’t hand code it? Smart developers use smart tools. I found this cool tool that does it all for me. it is called XSD2DB. Isn’t that an intuitive name? It is available download for here.

Tuesday, April 21, 2009

Your user profile was not loaded correctly! You have been logged on with a temporary profile.

This is not a problem that I feel you would encounter on a regular basis. I think I had a unique problem because of which I encountered this one. When you install an operating system it allows you to create a profile. Now I installed the machine at home. Which means I was not on the corpnet of Microsoft which means I could not log on to the domain. So when I created a profile named after my alias, it was considered as a local profile and not a domain profile. And a folder was created under “C:\Users” with my alias name.

I am not sure if this makes any sense or not, but hey, I am a software program writer not a network administrator. So please excuse my jargon. Anyway, when I actually logged on to the domain with my brand new operating system the next day, a new profile had to be created for the domain. Now since there was a folder already with my alias name in “C:\Users” the brand new operating system create a brand new profile with in the format <alias.domain> so now there was a “.” in my profile directory name.

What happens is this “.” sometimes creates problems in installing certain software. I got the error message saying “There is an invalid character in the directory path of My Documents”. I checked the path and could find only one anomaly. And no points (“.”) for guessing what.

So I decided I will rename the profile directory. I straight away went to the directory and though I would rename it to something else. of course it wouldn’t let you. So I thought I would log on as a local administrator and then do it. Also I made sure that I start windows in safe mode.

After Logging on I backup my documents, and delete the profile and assume that the next time I log on, it will automatically create the new directory for me. Guess what… Not that easy…

So after a long research I found out that there are registry entries out of which windows reads the location of the profile directory. So if it doesn’t find the directory at the specified location, it creates a temporary directory and logs you on with a temporary profile. And after the log on is complete, it gives you that message.

So here is what you do to save your life. Please do this only if you have already deleted your profile and did not take backup. If you are doing your research before you have messed with your machine, please skip these steps and refer below.

  1. Log on with local administrator account, preferably in safe mode. To boot the machine in safe mode, Click F8 during boot.
  2. Click Start + Run and type in regedit and then Enter.
  3. Open HKEY_LOCAL_MACHINE
  4. Open Software
  5. Open Microsoft
  6. Open Windows NT
  7. Open Current Version
  8. Open ProfileList
  9. Here you will see keys that belong to each profile. To find your problematic profile navigate to each key and refer to the ProfileImagePath entry on the right hand side.
  10. Once you find your problematic profile, just delete the key. This means delete the folder on the left hand side tree view that contains your alias in the ProfileImagePath entry.
  11. Restart machine.

There is another way you can actually backup your profile and create a new one.

Click on “Start”, Right click “Computer” and go to “properties”

Click on “Change Settings”

image

Go to the “Advanced” tab and click on User Profiles “Settings” button

image

image

“Change type” will allow you to change your profile type between Roaming and Local Profiles

“Delete” will delete that profile. Including the registry entries and everything.

“Copy To” will back up your profile. It is always advisable to backup your profile from here rather than from anywhere else. Your profile contains more than you can see. Hidden Files, System Files, etc. This takes care of everything in a safe manner.

Hope this helps.

Wednesday, January 28, 2009

Are you Eager? Or are you Lazy? Or are you both on a case to case basis...??

Entity Framework, Eager Loading and Lazy Loading, my own 2 cents. For those new to Entity Framework, we are talking about the patterns that you can use to load related objects. The strategy by which you would load entity objects that are related to the one in question. There is a beautiful resource that mentions it all. I do not think there is any elaboration required in that matter. But this is not the meat of the matter.

image How do you design an application that uses Entity Framework as a data access strategy? There are a no. of things to consider. The apparent answer all over the Internet is the Repository Pattern (ref: http://blogs.infosupport.com/blogs/willemm/archive/2008/08/18/Using-ADO.NET-Entity-framework-with-the-repository-pattern.aspx, http://blogs.microsoft.co.il/blogs/kim/archive/2008/11/12/data-access-with-the-entity-framework.aspx, http://www.simonsegal.net/blog/2009/01/13/entity-framework-repository-specifications-and-fetching-strategies/). The purpose of the repository pattern is "A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper (165), that isolates domain objects from details of the database access code." All said and done, we write the repository to abstract the CRUD from the Application Layer. This way, simply put, we don't need to write separate routines to do CRUD behaviour on every entity type. The functions look something like this:

-------------------------------------------------------------------------------------------

/// <summary>
/// Returns the required querable object to the caller
/// </summary>
/// <typeparam name="T">Generic Object</typeparam>
/// <returns>IQueryable<T></returns>
private IQueryable<T> GetTable<T>()
{
     IQueryable<T> result = null
     string type = typeof(T).Name; 
     ObjectQuery query = Context.CreateQuery<T>(type);
     result = (
IQueryable<T>)query;
     return result;
}

This routine is called like this.

////<summary>
////Return all instances of type T.
////</summary>
////<returns></returns>
public virtual IEnumerable<T> All<T>()
{
     System.Data.Linq.
DataLoadOptions dlo = new System.Data.Linq.DataLoadOptions();
     return GetTable<T>();
}

And this in turn is called like this:

public IEnumerable<Employee> GetEmployees()
{
     IEnumerable<Employee> employees = this.dbProvider.All<Employee>();
     return employees;
}

-----------------------------------------------------------------------------------------------------------------------------

Now if you see, we have one function retrieve all types of entity objects. Now let's get to the actual topic in hand. Eager loading and lazy loading. I cannot opt for any of the mentioned patterns, because I do not have the type of the pattern that I am going to return at design time. I have already postponed that by using Generics. Just last night I learnt from Daniel Simmons that Framework 4.0 they are planning to add a property to Context object in order to opt in implicit lazy loading.

While I am still trying to figure out a good way of working around eager loading and lazy loading, as of now (before 4.0 arrives) I am firing separate queries to get all types of related objects. And interestingly, once I fire the queries for the related objects and enumerate them, the principal object at hand gets populated with related objects. So next time you want to reference the related objects, just go ahead and use the beautiful sentence completion features such as this: "txtAddressLine1.Text = employee.EmployeeAddress.First().Address.AddressLine1;"

Thursday, January 15, 2009

StyleCop and Good Code

So you are serious about your code quality huh... well StyleCop is a fantastic tool to ensure that. The best part is, it integrates with Studio 2008. It is simple.

  1. Go to This Location, click on downloads and download the latest version of StyleCop. As of now it is the version 4.3
  2. Install StyleCop. It asks you information about integration. Let it integrate with Studio for the moment.
  3. Fire up Visual Studio
  4. Click on Tools and say Run StyleCop and look at the 1001 warnings that StyleCop gives.

Now when you use StyleCop, most of the warnings are not what you really want to work upon. Like Documentation, for instance, imagewho cares whether there is a blank space line above a comment or not...? So you can go to Solutions Explorer and click on Style Cop Settings. This will bring up the "Microsoft StyleimageCop Project Settings" Dialogue box which will allow you to customize your rules set. Allow you to enable / disable rules as per your own special requirements / whims / fancies / moods... :)

It is a fun little tool and I could have written more about it but then I decided that I won't spoil the fun. You guys go ahead and explore.

Thursday, January 08, 2009

Entity Framework FAQ

Lately everyone in my team and around my bay have been talking about Entity Framework. Well since I have been an early adopter, writing my small apps using Entity Framework and fighting for it on my project, people have been coming to me to ask questions. I have been taking pride in answering them (happy to help), most of the times... until lately... since I have been working on too many things...

I just came across an FAQ which pretty much covers it all (thanks Daniel...!). I thought I will add it to my browser favourites. But then I thought that would just help me and not everyone.

Happy to help... :)

Sunday, January 04, 2009

New year resolutions

  1. Move to domain: Focus more on domain knowledge than on Technicalities. My blog will be filled more with how a technology applies in solving a business problem rather than how to solve a technical problem.
  2. I will track my investments: All these years I have been only investing to save tax. It is mandatory to invest in Insurance linked funds and so I invested. It increased my salary a little bit. I didn't look at it from a returns perspective. After I got married October last year, I was made to realize by my investment savvy wife that saving tax is just not enough. There is potential to make our lives better and that I should. That's another reason why I love my wife so much. She brings out the best in me and makes me want to get better every day
  3. I will cut costs: Yes I have lived a lavish life. Beyond my means, beyond what a sane person should do. This year I will not put money into things that I do not have to. Every extra penny that I have after spending the constant costs, I will save.
  4. I will Make a savings Plan: Every month after I get my salary, approximately 60% of my salary goes directly into Infrastructure costs (big word...!!) Rent, Maid Salaries, car EMI, House hold expenses for mom and dad and household expenses for us are infrastructure costs. The rest of the money is slowly spent over the month on small things such as eating out and such. Since I am not keeping track of where the money is going, I end up spending more. Up-front investment is required. A savings plan is required which gets implemented as soon as I get the salary.
  5. Insurance Policies: Re-activate the LIC policy that became dormant last year. Save for the new annual tax benefit investments on a monthly basis rather than on an annual basis. It is always a fight around December when I have to make the savings towards the end of the financial year.
  6. Gym: Last entire year I was extremely irregular in gym. I need to get back into discipline
  7. Guitar: At least 5 hours of cumulative practice over a week should be good.