EntityFramework-Reverse-POCO-Code-First-Generator
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard
Support for sql_variant data type
Hi,
Is there a solution for working with fields of type "sql_variant" ?
I have a couple of fields defined as such, which I have to read, but EF throws an error:
System.InvalidOperationException : The store type 'sql_variant' could not be found in the SqlServer provider manifest
Perhaps some work around exists? I googled about this problem but it doesn't seem that EF6 supports sql_variant, only the preview version of EF Core.
Any help appreciated, thanks!
Everyone recommends staying away from sql_variant's. Bad habits to kick : choosing the wrong data type and the heading Using SQL_VARIANT at all, etc, etc.
If however you are not designing the database, but are stuck with it, could you create another computed column varchar(max) which takes the sql_variant and converts it. Then hide the sql_variant column in the generator using UpdateColumn callback function and setting the variant column to hidden ?
Yes, I know it's a bad practice to use sql_variant, but I did not setup the DB, it came directly from Microsoft as part of SQL server SSIS system table. I will try your solution, thanks!
The only thing I could do to help in the generator is to automatically exclude all the sql_variant columns.
Yes, that would be nice! Could you set it up as an optional setting that we can toggle in the generator?
@sjh37 "Bad habits to kick : choosing the wrong data type"? There is a purpose for this data type, in my industry we have meters that produce the same set of columns (pressure, temperature, etc.) but one device may only support int's, one device type may support single precision floats and so on. We need to store the original binary value for the audit trail (so we cannot just cast everything to a double / decimal).