Do Entity Framework Provide Utility that convert DB Type To C# Type? -


i m building dynamic class using reflection , type builder , , want know how can direct type casting c# type

currently way m doing , kind of thing provided ef ?

 case "uniqueidentifier":                 return typeof(guid);             case "bit":                 return typeof(boolean);             case "nvarchar":                 return (typeof(string));             case "datetime":                 return typeof(datetime);             case "float":                 return typeof(double);             case "int":                 return (typeof(int)); 

thanks

update assume there no utility provided ef till publicly accessible.the answer accepted has nothing ef. rather different library there.

ryszard dżegan has given answer can not used outside tt templates or edmx (or may didn't know)

i dont know such public method (i think there none... may accepted answer)

however, try uncompile sqlmetal.exe, can have idea of how default associations implemented internally:

in class linqtosqlshared.utility.dbtypesystem (internal class) can find method:

internal static type getclosestruntimetype(sqldbtype sqldbtype) { switch (sqldbtype) {     case sqldbtype.bigint:         return typeof(long);      case sqldbtype.binary:     case sqldbtype.image:     case sqldbtype.timestamp:     case sqldbtype.varbinary:         return typeof(binary);      case sqldbtype.bit:         return typeof(bool);      case sqldbtype.char:     case sqldbtype.nchar:     case sqldbtype.ntext:     case sqldbtype.nvarchar:     case sqldbtype.text:     case sqldbtype.varchar:         return typeof(string);      case sqldbtype.datetime:     case sqldbtype.smalldatetime:     case sqldbtype.date:     case sqldbtype.datetime2:         return typeof(datetime);      case sqldbtype.decimal:     case sqldbtype.money:     case sqldbtype.smallmoney:         return typeof(decimal);      case sqldbtype.float:         return typeof(double);      case sqldbtype.int:         return typeof(int);      case sqldbtype.real:         return typeof(float);      case sqldbtype.uniqueidentifier:         return typeof(guid);      case sqldbtype.smallint:         return typeof(short);      case sqldbtype.tinyint:         return typeof(byte);      case sqldbtype.xml:         return typeof(xelement);      case sqldbtype.time:         return typeof(timespan);      case sqldbtype.datetimeoffset:         return typeof(datetimeoffset); } return typeof(object); } 

edit:

  • see this reference

  • there method static sqldbtype parse(string stype) in same class returns enum sqldbtype sql type string definition.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -