Home > Developing Using CodeFluent Entities, Importers, SQL Server > Defining type mappers when importing a database using the Importer Wizard

Defining type mappers when importing a database using the Importer Wizard


You can use the Importer Wizard to import an existing data base as a CodeFluent Entities model. You can access the Importer from the Modeler or the solution explorer on your CodeFluent Entities project (right click).
 

The Importer Wizard

The Importer Wizard


 
The importer makes a mapping between the data source types and the CodeFluent Entities types. But, you may want to define your own mapping configuration for a given type.
 
To do that, go to the “advanced properties” of the Importer Wizard and select “Type Mappers” under the “Input Mapping” group and add your type mapper.
 
Type Mappers Configuration

Type Mappers Configuration


 
Add an Importer Type Mapper

Add an Importer Type Mapper


 
Let’s say I am importing a SQL Server 2012 database and I have a field of type “time” (more information about SQL Server 2012 type mapping here), well I would like to have a CLR type “TimeSpan” mapped to it. When I take a look at the imported model I can see that the mapped type is “time”, but when I generate the Business Object Model (BOM) layer I have a property of type “System.DateTime (nullable)”. This is because the SQL Server type “time” did not exist before the SQL Server 2008 version.
 
SQL Server time type

SQL Server time type


 
time to DateTime mapping

time to DateTime mapping


 
So we can define a “type mapper” for the SQL Server type “time”.
 
elapsedtime mapper

elapsedtime mapper


 

We could also have chosen “System.TimeSpan”, “timespan” or “duration” as the “Type Name”.

 
And now we have a CLR type “System.TimeSpan (nullable)” in our BOM for a SQL Server 2012 type “time”.
 

time to TimeSpan mapping

time to TimeSpan mapping


 

Remember that you can save your Importer Wizard configuration.

 
You can find more resources about the Importer Wizard here.
 
 
Regards,
 
Pablo Fernandez Duran
 
 

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s