Monthly Archives: April 2010

Gopas TechEd 2010

Úplně bych zapomněl na letošní Gopas TechEd. Vlastně už začal, takže jsem pozadu. Nicméně to nejlepší teprve přijde. ;)

Mám celkem tři přednášky. První je již zítra a pokrývat bude “.NET4 – PLINQ, Task Parallel Library”. Já sám jsem blázen do všeho paralelního, a pokud jste jako já nemůžete vynechat. ;) Druhá, ve čtvrtek, je na téma “Novinky v Entity Framework 4.0″. Co říci více? Název je myslím jasný. A poslední, taktéž ve čtvrtek, je “ADO.NET vývoj s Firebirdem”. No pokud si nemyslíte, že existuje jen MS SQL Server a chcete se dozvědět něco (a možná zkusit) o jedné z alternativ, rozhodně přijďte – doufám, že zodpovím všechny vaše otázky a nalomím vás. :)

Program poskytne informace kde a kdy se vše koná.

TortoiseSVN PowerShell aliases improved

Some time ago I wrote about creating PowerShell aliases for commit and update for TortoiseSVN. But I needed little bit more flexibility with path so I added a parameter with default to ..

 function fn_update($path = ".") {tortoiseproc /command:update /path:$path}
 function fn_commit($path = ".") {tortoiseproc /command:commit /path:$path}

TabIndex tool in Visual Studio

I remember from old times that I was using some plug-in into Delphi IDE to set tab order by clicking on components in order you wanted the ordering to be. Today I was reviewing the tab ordering in ID3 renamer as somebody reported in forum it’s wrong. I was scared doing all the work through Properties window in Visual Studio.

But it turned out, that Visual Studio has this tool in the box. You can find the description here. You’ll simply select form, go to View > Tab Order and click on different controls to change the ordering. You see the numbers directly in designer and go through possible options by clicking.

Pretty nice, don’t you think?

New Translate<T> and ExecuteStoreQuery<T> (+ExecuteStoreCommand) on ObjectContext in Entity Framework v4

I don’t know whether it’s somewhere specifically pointed, but the ObjectContext in Entity Framework v4 has two (three) new handy methods. And I like these.

It’s kind of escape hatch similar to DefiningQuery. First method is Translate<T>. It takes DbDataReader and materializes the data back into entities. It’s similar to Materialize method from EFExtensions. If you some code in pure ADO.NET and you don’t have time or resources to redo it in EF (or it’s way easier old way) you can rewire the result into existing objects. I like it. Whenever I’ll feel I need to get dirty (and probably due to performance reasons) I can do it pretty easily.

using (testovaciEntities ent = new testovaciEntities())
{
	IDbConnection conn = (ent.Connection as EntityConnection).StoreConnection;
	conn.Open();
	using (IDbCommand cmd = conn.CreateCommand())
	{
		cmd.CommandText = "select * from master";
		using (DbDataReader reader = (DbDataReader)cmd.ExecuteReader())
		{
			MASTER[] result = ent.Translate(reader).ToArray();
			Console.WriteLine(result.Length);
		}
	}
}

The other method is similar and simplifies the process of getting dirty if you simply need to run you fine tuned query with neat and sexy constructs. :) It’s ExecuteStoreQuery<T>. This method simply allows you to run any sql command directly in store language (thus you can use all features your database offers) and fetch and materialize back resulting entities. Similar to this is ExecuteStoreCommand which is similar to ExecuteNonQuery from pure ADO.NET. But you can do this without the method easily too, the method is just more convenient.

BTW also note that the Translate method isn’t adding the entities into context, it’s just about fetching and materializing.

Mapping and metadata information could not be found for EntityType (InvalidOperationException)

I updated my pretty big model today. Added absolutely simple table, no foreign keys, basic datatypes, simple PK. When I was calling CreateObjectSet<T> what a surprise - InvalidOperationException saying “Mapping and metadata information could not be found for EntityType”. That’s not so much descriptive.

Quick search thru internet resulted in suggestion that I’m missing some property in my POCO classes. I was not. I double checked it and I know that Entity Framework throws MetadataException listing all the missing properties (yep, I was there too, but it’s easy to fix). Another reason I found was that the metadata are not placed into resources or things are screwed up because of mixing two models in one project (to be clear, it is possible, but you have to carefully design your namespaces and names). Not the case either. I have only one model, metadata are there properly, other entity sets were working fine.

After loosing my mind slightly I found, rejected and then believed back again that it’s true, that you have misspelled property. I first rejected the idea because it was mixing the misspelled property and missing property together. And I knew about the MetadataException case. But the misspelled property actually results in InvalidOperationException exception with useless message.

Hopefully you’ll believe this (or any other solution found) faster than I did. :)

EDM designer as reverse engineering tool

Yesterday there was a question in one list I’m following. Simply to share some recommendation for tool being able to reverse engineer the database structure and show some E-R diagram.

After I get time to reply with some suggestions, idea came to my head. The EDM designer is actually kind of reverse engineering tool. Did you realized that?

As the EF support for major database platforms is available it’s easy to get a basic overview of the database structure without leaving Visual Studio. Sure it doesn’t have some cool features of specialized programs, but on the other hand it’s already in VS (Express edition is free) and you don’t have to buy and install another product (if you’re not doing this often, but then you’re probably using the specialized program).