PowerCMD – Console Awesoness

Consoles are back in vogue for some strange reason. Everyone wants cholocatey and other power tools to run on the command line. With stuff like mongodb, node etc.. running on the command line we need our windows command prompt to keep up with the times. If you thought Console2 was awesome then read on to find about PowerCMD.

  • Step 1.
    Go download it from here Powercmd
  • Step 2.
    Always run it as admin. On Windows 8 you can do it as shown below in the screenshot:
    Assigning admin privelges to PowerCMD Administrator Privileges for PowerCMD

  • Step 3. Start assigning your favourite shells to PowerCMD. Go to Tools -> Customize then set it up as below ( I take mongodb as the example)
    Customisation
  • Step 4.
    Start all the shells ( if you want to ) and watch it come alive.
    Press Ctrl + Enter to go to full screen mode.
    You can choose from several ( Zoink there are many and all are useful in some case or the other )
    Full Screen and Layout Aesomeness Full Screen and Layout Aesomeness
  • Step 5.
    Ever missed having the Environment Variables alongside your CMD. Go to View -> Watch Environment Variables.
    EnvironmentVariables EnvironmentVariables

All of this is neat and awesome. But this will cost you money as well. If you think tab completion thrown in with the above features makes it worth it, you can think of buying it. It is awesome, I hope someone decides to fix to the Windows CMD from the ground up at Microsoft.

Advertisements

Entity Framework – Table Per Type – Gotcha

Entity Framework Table Per Type (TPT) implementation has a little gotcha ( little is really relative ). When we create table per type we will have orphan rows if the parent gets deleted and there will be orphan rows in the parent if the child gets deleted. This causes a funny picture to emerge with very bad consequences.

Gotcha

Sad Panda

Now, to get around this my simple workaround was to alter the relationships in my seed method.

context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Match] DROP CONSTRAINT [FK_ParikshaDev.Match_ParikshaDev.Questions_QuestionId]" );
context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Match] ADD CONSTRAINT [FK_ParikshaDev.Match_ParikshaDev.Questions_QuestionId] FOREIGN KEY (QuestionId) REFERENCES [ParikshaDev].[Questions] (QuestionId) ON DELETE CASCADE" );

context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Brief] DROP CONSTRAINT [FK_ParikshaDev.Brief_ParikshaDev.Questions_QuestionId]" );
context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Brief] ADD CONSTRAINT [FK_ParikshaDev.Brief_ParikshaDev.Questions_QuestionId] FOREIGN KEY (QuestionId) REFERENCES [ParikshaDev].[Questions] (QuestionId) ON DELETE CASCADE" );

context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Choice] DROP CONSTRAINT [FK_ParikshaDev.Choice_ParikshaDev.Questions_QuestionId]" );
context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Choice] ADD CONSTRAINT [FK_ParikshaDev.Choice_ParikshaDev.Questions_QuestionId] FOREIGN KEY (QuestionId) REFERENCES [ParikshaDev].[Questions] (QuestionId) ON DELETE CASCADE" );

context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Custom] DROP CONSTRAINT [FK_ParikshaDev.Custom_ParikshaDev.Questions_QuestionId]" );
context.Database.ExecuteSqlCommand( @"ALTER TABLE [ParikshaDev].[Custom] ADD CONSTRAINT [FK_ParikshaDev.Custom_ParikshaDev.Questions_QuestionId] FOREIGN KEY (QuestionId) REFERENCES [ParikshaDev].[Questions] (QuestionId) ON DELETE CASCADE" );

Fix!

Better Panda

There are things that can be better in this code. We can have the Schema name and the Table name statically typed with the help of the context. The relationship name was arrived at by making an educated guess about the relationships and then confirming them by having a look at the db that was generated previously.
I would consider this as a bug in EF. I didn’t see any way to configure this behaviour with the fluent api. I expected this to be clearly stated in the documentation or a flag or a switch be made available in the api for configuration.