问题标签 [sql-variant]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 实体框架 sql_variant 作为主键
对于一个项目,我使用 EF Core 5.0 搭建现有数据库。
数据库有一些表,其中sql_variant
列作为主键的一部分。
该模型将属性创建为“对象”。
此属性的基础OnModelCreating
:
当我尝试测试此自动脚手架时,我收到错误消息:
'ProdOrderRoutingLine.OperationNo' 属性不能用作键,因为它具有不实现 'IComparable'、'IComparable' 或 'IStructuralComparable' 的类型 'object'。使用 'OnModelCreating' 中的 'HasConversion' 将 'object' 包装为可以比较的类型。
所以我尝试了很多转换sql_variant
为字符串或对象或...与比较器。为了简单起见,我将尝试将其转换为具有默认比较器的字符串。
在这里,我将我的属性更改为string
如果我将其保留为object
我得到相同的错误:
'ProdOrderRoutingLine.OperationNo' 属性是当前数据库提供程序不支持的'string' 类型。更改属性 CLR 类型,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略该属性
任何想法如何克服这个问题并将现有的sql_variant
用作部分主键?
OnModelCreate
首要的关键:
模型的一部分:
c# - sql_variant and real and float in combination with WHERE smaller statements
I am using a sql_variant field at MS SQL Server 2019.
Select queries containing a WHERE <
clause are not working when inserting a number as real or float. It does work when insering as numeric. Not working means, smaller values were not selected.
Unfortunately there is no C# numeric sql type, but only SqlDbType.Float or SqlDbType.Real.
Any idea how use sql_variant as float or real in combination with WHERE smaller statements?