gpt4 book ai didi

c# - LINQ to Entities 仅支持在 Update 1 RC 降级为 CTP 后转换 EDM 原语或枚举类型

转载 作者:行者123 更新时间:2023-11-30 21:54:02 26 4
gpt4 key购买 nike

在我安装 VS2015 Update 1 RC 之后,由于 RC 中的许多错误,以下代码无故停止工作,后来降级为 Update 1 CTP

获得:

Unable to cast the type 'EFCastTest.ResourceGroup' to type 'EFCastTest.ISortable'. LINQ to Entities only supports casting EDM primitive or enumeration types

class Program
{
static void Main(string[] args)
{
var sorted = GetSorted<ResourceGroup>();
}

static T[] GetSorted<T>() where T : class, ISortable
{
var ctx = new Model1();
var sorted = ctx.Set<T>().OrderBy(x => x.SortOrder).ToArray(); // <- in this line
return sorted;
}
}
public interface ISortable
{
int? SortOrder { get; }
}
public partial class ResourceGroup : ISortable
{
public int? SortOrder { get; set; }
}

最佳答案

这是对 C# 编译器 (https://github.com/dotnet/roslyn/issues/4471) 中的错误修复不完整的表现,该错误引入了一些回归。原始错误(在 RTM 中引入)从表达式树中删除了一些转换节点,并导致基于 LINQ to SQL 的现有应用程序中断。不完整的错误修复(包含在 Update 1 CTP 中)在添加 cast 节点方面过于激进,导致 EF 出现各种中断。最终修复包含在 Update 1 RC 中,并恢复了 C# 编译器在 Roslyn 之前的行为。不幸的是,除非您重新安装 RC,否则我不确定您是否可以使用 RC 中包含的编译器。

关于c# - LINQ to Entities 仅支持在 Update 1 RC 降级为 CTP 后转换 EDM 原语或枚举类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33549942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com