EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Support for sql_variant data type

Open ClassyCircuit opened this issue 7 years ago • 5 comments

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!

ClassyCircuit avatar Mar 22 '18 13:03 ClassyCircuit

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 ?

sjh37 avatar Mar 22 '18 17:03 sjh37

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!

ClassyCircuit avatar Mar 23 '18 06:03 ClassyCircuit

The only thing I could do to help in the generator is to automatically exclude all the sql_variant columns.

sjh37 avatar Mar 23 '18 09:03 sjh37

Yes, that would be nice! Could you set it up as an optional setting that we can toggle in the generator?

ClassyCircuit avatar Mar 23 '18 10:03 ClassyCircuit

@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).

jasonrichardcraig avatar Sep 17 '20 10:09 jasonrichardcraig