Reputation: 85
When using EF 4.1 Code First, is it possible to create User-Defined Data Types for your schema?
Upvotes: 1
Views: 1887
Reputation: 364279
Simple answer is no.
Longer answer:
Current EF implementation leads to multiple issues when trying to use user defined types:
Seed
method of database initializer (as often used for other database constructs like triggers or indexes). To make this work you must create whole new initializer by implementing IDatabaseInitializer
and separate database creation and table creation because custom type definitions must be between them. Here is some example how to create database initializer (this one will recreate tables every time you run the application).ColumnAttribute
and HasColumnType
in fluent API will accept custom type. So your mapping must specify basic primitive SQL types and these custom types will be used in tables DDL produced by EF. So unless custom database initializer post-process those generated SQL scripts and replaces basic types with custom types (really ugly solution) tables will not use them.Upvotes: 1