It's a kind of tricky thing.
First of all read this article Model first if you have not yet.
Then create separate class library project with custom IGenerateActivityOutput
implementation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Data.Entity.Design.DatabaseGeneration.OutputGenerators;
using System.Activities;
namespace MyCSDLToSSDL
{
public class MyCsdlToSsdl: IGenerateActivityOutput
{
private CsdlToSsdl _generator;
public MyCsdlToSsdl()
{
_generator = new CsdlToSsdl();
}
public T GenerateActivityOutput<T>(OutputGeneratorActivity owningActivity, NativeActivityContext context, IDictionary<string, object> inputs) where T : class
{
var str = _generator.GenerateActivityOutput<T>(owningActivity, context, inputs) as string;
return str.Replace("Type=\"datetime\"", "Type=\"smalldatetime\"") as T;
}
}
}
The next step is to modify database generation workflow.
- Locate TablePerTypeStrategy.xaml in your file system.
- Copy this file to the same folder with different name. TablePerTypeStrategy_smalldatetime.xaml for example. Open it with VS.
- Change
OutputGeneratorType
of CsdlToSsdlAndMslActivity
to "MyCSDLToSSDL.MyCsdlToSsdl, MyCSDLToSSDL"
. Double quotes are required.
- Change database generation workflow property to "TablePerTypeStrategy_smalldatetime.xaml (VS)".
- Try to generate database from model.
Looks very much like a workaround but it works. :) Hope it helps!