tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Type mapper in Entity Framework 4.1

22 Mar 2011 1 mins Entity Framework

Even if you remove all conventions when using Code First you might get errors from Entity Framework about not being able to properly map some items. The reason is type mapper. In RC (and very probably in RTM as well) it’s not implemented as convention, hence always kicks in.

In this case the Ignore method comes into play. For instance I have in my code property:

public CultureInfo Locale
{
	get { ... }
	set { ... }
}

and I’m not mapping it at any place. But Entity Framework will still complain about pieces of CultureInfo not being properly mapped. But in EntityTypeConfiguration can make Entity Framework to ignore it. For example:

class FooBarConfiguration : EntityTypeConfiguration<FooBar>
{
	public FooBarConfiguration()
	{
		// ...
		this.Ignore(x => x.Locale);
		this.Map(...);
	}
}

At first I was confused, but after quick email exchange with EF team the “issue” was clear.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.