data annotations - EF5 (Code First) Dynamic/Variable TypeName -


i have class data annotation properties typename specified. works should. unit testing purposes want use sql compact database instead of sql server database. sql compact not support xml datatype. recommend use ntext. catch doens't affect entity @ both xml , ntext map type system.string. creating database on fly though hassle. want typename="xml" when connecting sql server , typename="ntext" when connecting sql compact.

public class technicalstructure {     [column("structureattributes", typename = "xml")]     public string structureattributes { get; set; } } 

so found answer. removed typename attribute-property affected class property , overrode onmodelcreate method in dbcontext class. in there specified datatype. here code example:

if (isinunittestmode) { modelbuilder.entity<technicalstructure>() .property(x => x.structuretype) .hascolumntype("nvarchar");  modelbuilder.entity<technicalstructure>() .property(x => x.structureattributes) .hascolumntype("ntext"); } else { modelbuilder.entity<technicalstructure>() .property(x => x.structuretype) .hascolumntype("char");  modelbuilder.entity<technicalstructure>() .property(x => x.structureattributes) .hascolumntype("xml"); } 

Comments