简体   繁体   English

实体框架-不支持“ ColumnName”列的类型。 类型是“对象”

[英]Entity Framework - The type of column 'ColumnName' is not supported. The type is 'Object'

I wrote a piece of code 6 months ago, which worked fine and was deployed in multiple environments. 我在6个月前写了一段代码,效果很好,并已部署在多个环境中。 I have got a new enhancement now and when I try to run the same code, it strangely gives me an error. 我现在有了一个新的增强功能,当我尝试运行相同的代码时,很奇怪地给我一个错误。 I search online but nothing much helpful. 我在网上搜索,但没有什么帮助。 Below is the code in concern: 以下是相关代码:

var parameter = new SqlParameter("@SearchCriteria", SqlDbType.Structured);
parameter.Value = searchCriteria;
parameter.TypeName = "dbo.SearchCriteria";

var output = entities.Database.SqlQuery<tablename>(
    "dbo.storedprocedureName @SearchCriteria", 
    parameter).ToList<tablename>();

It gives me the error 它给我错误

The type of column 'SelectedValue' is not supported. 不支持“ SelectedValue”列的类型。 The type is 'Object'. 类型为“对象”。

The same deployed code is still in running on other servers without any issues. 相同的部署代码仍在其他服务器上运行,没有任何问题。 Not sure what changed in my pc!! 不知道我的电脑发生了什么变化!

My Table type definition: 我的表格类型定义:

    CREATE TYPE [dbo].[SearchCriteria] AS TABLE(
    [SelectedAttribute] [varchar](50) NULL,
    [SelectedCriteria] [varchar](50) NULL,
    [SelectedValue] [varchar](50) NULL)

I believe this error is not coming out of stored procedure but coming in ADO.NET / Entity Framework even before calling up the stored procedure. 我相信这个错误不是来自存储过程,而是来自ADO.NET/Entity Framework,甚至在调用存储过程之前也是如此。 I kept a trace using SQL Profile so the call did never hit DB. 我使用SQL Profile进行了跟踪,因此该调用从未到达DB。 I tried to run SP directly on SSMS and SP is working fine. 我试图直接在SSMS上运行SP,并且SP运行正常。 So, I could see it is something to with either Entity Framework or ADO.NET. 因此,我可以看到它与实体框架或ADO.NET有关。

I had an object in C# which stores SearchCriteria and gets converted to DataTable before being sent to Stored Procedure using EF. 我在C#中有一个对象,该对象存储SearchCriteria,并在使用EF发送到存储过程之前被转换为DataTable。

One of the fields "SelectedValue" was declared as "Object". 字段“ SelectedValue”之一被声明为“ Object”。 I changed that to "string" and everything is working fine. 我将其更改为“字符串”,并且一切正常。

I have absolutely no idea how this code has been working so far and why it broke now!! 我绝对不知道这段代码到目前为止是如何工作的,为什么现在就坏了! I was the one who wrote it and I'm the who modified it now so no middle person changes as well :) 我是写它的人,现在是修改它的人,所以中间人也没有改变:)

Old Class: 旧类:

public class SelectionCriteria
{
    public string SelectedAttribute { get; set; }
    public string SelectedCriteria { get; set; }
    public object SelectedValue { get; set; }
}

Modified Class: 修改后的类:

public class SelectionCriteria
    {
        public string SelectedAttribute { get; set; }
        public string SelectedCriteria { get; set; }
        public string SelectedValue { get; set; }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架“不支持每种类型的多个对象集。 ” - Entity Framework “Multiple object sets per type are not supported. ” 不支持SQL Server表值参数列。 类型是&#39;对象&#39; - SQL Server Table Valued Parameter column is not supported. The type is 'Object' 不支持每种类型的多个对象集。 对象集IdentityUsers&#39;和用户都可以包含类型的实例 - Multiple object sets per type are not supported. The object sets IdentityUsers'and Users can both contain instances of type 不支持媒体类型“”。 有效的媒体类型:[*/*] - Media type '' is not supported. Valid media types: [*/*] 实体框架alter column type - Entity Framework alter column type EnumDropDownList用于使用反射时抛出“不支持返回类型&#39;System.Object&#39;。” - EnumDropDownListFor using Reflection throwing “Return type 'System.Object' is not supported.” 如何解决实体框架的“不支持每种类型的多个 object 集”问题 - How to solve the "Multiple object sets per type are not supported" problem with Entity Framework 实体框架实体属性作为对象类型 - Entity Framework Entity properties as Object type 不支持服务类型IAssembliesResolver。 参数名称:serviceType - The service type IAssembliesResolver is not supported. Parameter name: serviceType “无法修改列[ColumnName = Id]”-使用Entity Framework 5 - “The column cannot be modified [ColumnName = Id]” - Using Entity Framework 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM