Menu Close

Category: C#

Entity Framework’s quirk: imagined ambiguity

Triple-facepalm

Lots have been said about Entity Framework, in past mostly bad things. Lately I hear more and more voices speaking in advantage of this library. It is being said that it has reached maturity point and is actually usable now. Of course it was usable earlier, but it had its quirks. Unfortunately some are still there. I have recently found one that I couldn’t really believe is true. I had(also severe) problems with EF before, but this one is absolutely no-go for me. If exception message below reads familiar, then most probably you are experiencing it too.

 

Schema specified is not valid. Errors:

The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type ‘<<entity name>>’. Previously found CLR type ‘<<namespace1.entity name>>’, newly found CLR type ‘<<namespace2.entity name>>’.

NRW2013 – Conference day

20131011_161645After living 5 months in Germany, given opportunity and encouragement I finally got from under the rock and went to IT event – NRW2013 conference. Language barrier is still big obstacle, but, as it turned out, listening to well illustrated talks on subjects that touch more or less known domain is not very hard. NRW2013 conference consists of 2 days – one workshop day and one conference day. I attended only conference day.

Custom Tool Error when updating service reference in VS 2010[Solved]

Day as usual, I was assigned some task to do in project, that I am working on. To meet the requirement I had to update service reference to one of WCF web-services included in solution. This was nothing new, service was in this solution almost from the start of the project, even before I got to work on it, being one of it’s central parts. I was really surprised, when operation, that I’ve completed many times before failed with error:

Error    27    Custom tool error: Failed to generate code for the service reference ‘<<serviceName>>’. Please check other error and warning messages for details.

After looking through the warnings I’ve found that three of them seemed to be the causes of this error. They looked something like this:

Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
<some more info, some XPaths>

and alike for “port” and “portType”. I’ve looked at Reference.cs – there was no code inside, only some generated, commented out header.

That’s a bummer! After googling I’ve found that most popular solutions were:

  • remove reference, restart VS, add it from scratch
  • try restarting machine
  • check “Reuse types from referenced assemblies”
  • if you have installed VS2012 uninstall it reinstall VS2010

First and second one did not work. Third one was no good solution. Well, it made service reference to update, but in project referencing it I had all types doubled, so ambiguous types references all over the place. Fourth solution did not help.

Different approach to reading data from SqlDataReader [source code included]

When reading data from SqlDataReader you have to know your select statement’s columns order to read and map data from database to your model. Often it looks somehow like this:

using (SqlDataReader reader = command.ExecuteReader())
{
	if (reader.Read())
		return new AnimalModel
		{
			AnimalId = reader.GetInt32(0),//or better with enum like that: AnimalId = reader.GetInt32((int)AnimalSelect.AnimalId)
			BirthDate = reader.GetDateTime(1),
			Name = reader.GetString(2)
			//etc...
		};
	else return null;
}

It’s a good practice to create enum representing select’s columns and using it instead of int indexes.
But wouldn’t it be better if you could just do it like that:

using (SqlDataReader reader = command.ExecuteReader())
{
	if (reader.Read())
		return reader.ReadObject();
	else return null;
}

CKEditor’s file manager and deleting files

FCKEditor's file manager with deleting filesFCKEditor is retired, but still widely used in many web applications. One of its great features is file manager that can be both invoked from editor or be used by itself. One of most painful limitations that this built-in file manager has is inability to delete files. But, as it turned out, it’s not a hard task to implement this functionality on Your own. In this post I’ll demonstrate how to do it in asp.net application(client-part is applicable for any other server-side framework).