Get the SQL Server Data Type as SqlDbType

Posts   
 
    
egutierrez
User
Posts: 7
Joined: 12-Nov-2018
# Posted on: 12-Nov-2018 16:51:02   

Hi,

I have a scenario where I need the SQL Server data type of each field, so I mean something like the SqlDbType enum.

When I get the DataType from the Entity what I get is a .NET Type, but in some cases I can't distinguish if the data type is binary, image, varbinary, timestamp because all of them are converted to byte[].

Is there any way I can get the Sql Server data type from the Entity?

The only solution I can imagine is to execute a raw SQL query like

SELECT * FROM INFORMATION_SCHEMA.COLUMNS

and get the data type from there, cast the data type to the enum

(SqlDbType)Enum.Parse(typeof(SqlDbType), typeName, true)

By the way, I'm using LLBLGEN 4.2 with no option to upgrade to version 5.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Nov-2018 06:09:41   
  • Do you need this information per entity basis in the generated code (i.e., consult the DB type of certain field, or all fields)?

  • Or Do you want to know this in LLBLGen Pro Designer?

  • Or, Do you just want an enum of db types and that's it?

David Elizondo | LLBLGen Support Team
egutierrez
User
Posts: 7
Joined: 12-Nov-2018
# Posted on: 15-Nov-2018 22:33:04   

The answers is:

Using DataAccessAdapterCore.GetFieldPersistenceInfo() I can get an object with the real data type configured in the DB with the IFieldPersistenceInfo.SourceColumnDbType property.