草庐IT

entity-system

全部标签

c# - 为什么 Contains() 运算符会如此显着地降低 Entity Framework 的性能?

更新3:根据thisannouncement,这已由EF团队在EF6alpha2中解决。更新2:我提出了解决此问题的建议。投票给它,gohere.考虑一个带有一个非常简单的表的SQL数据库。CREATETABLEMain(IdINTPRIMARYKEY)我用10,000条记录填充表。WITHNumbersAS(SELECT1ASIdUNIONALLSELECTId+1ASIdFROMNumbersWHEREId我为表构建了一个EF模型并在LINQPad中运行以下查询(我使用的是“C#语句”模式,因此LINQPad不会自动创建转储)。varrows=Main.ToArray();执行时间

c# - 为什么我不能引用 System.ComponentModel.DataAnnotations?

我正在尝试在我的WPF项目中使用DataAnnotations来指定字符串的最大长度,如下所示:usingSystem.ComponentModel.DataAnnotations;但是,我得到了错误Thetypeornamespacename'DataAnnotations'doesnotexistinthenamespace'System.ComponentModel'(areyoumissinganassemblyreference?)我见过其他示例,其中DataAnnotations确实存在于此命名空间中。我正在使用C#4。我有什么理由不能使用它吗?我该怎么做才能修复它?

c# - 为什么我不能引用 System.ComponentModel.DataAnnotations?

我正在尝试在我的WPF项目中使用DataAnnotations来指定字符串的最大长度,如下所示:usingSystem.ComponentModel.DataAnnotations;但是,我得到了错误Thetypeornamespacename'DataAnnotations'doesnotexistinthenamespace'System.ComponentModel'(areyoumissinganassemblyreference?)我见过其他示例,其中DataAnnotations确实存在于此命名空间中。我正在使用C#4。我有什么理由不能使用它吗?我该怎么做才能修复它?

c# - Linq Query 一直抛出 "Unable to create a constant value of type System.Object....",为什么?

以下是代码示例:privatevoidloadCustomer(intcustIdToQuery){vardbContext=newSampleDB();try{varcustomerContext=fromtindbContext.tblCustomers//keepsthrowing:wheret.CustID.Equals(custIdToQuery)//Unabletocreateaconstantvalueoftype'System.Object'.selectnew//Onlyprimitivetypes('suchasInt32,String,andGuid'){//ar

c# - Linq Query 一直抛出 "Unable to create a constant value of type System.Object....",为什么?

以下是代码示例:privatevoidloadCustomer(intcustIdToQuery){vardbContext=newSampleDB();try{varcustomerContext=fromtindbContext.tblCustomers//keepsthrowing:wheret.CustID.Equals(custIdToQuery)//Unabletocreateaconstantvalueoftype'System.Object'.selectnew//Onlyprimitivetypes('suchasInt32,String,andGuid'){//ar

c# - LINQ to Entities 仅支持使用 IEntity 接口(interface)转换 EDM 原语或枚举类型

我有以下通用扩展方法:publicstaticTGetById(thisIQueryablecollection,Guidid)whereT:IEntity{Expression>predicate=e=>e.Id==id;Tentity;//Allowreportingmoredescriptiveerrormessages.try{entity=collection.SingleOrDefault(predicate);}catch(Exceptionex){thrownewInvalidOperationException(string.Format("Therewasanerr

c# - LINQ to Entities 仅支持使用 IEntity 接口(interface)转换 EDM 原语或枚举类型

我有以下通用扩展方法:publicstaticTGetById(thisIQueryablecollection,Guidid)whereT:IEntity{Expression>predicate=e=>e.Id==id;Tentity;//Allowreportingmoredescriptiveerrormessages.try{entity=collection.SingleOrDefault(predicate);}catch(Exceptionex){thrownewInvalidOperationException(string.Format("Therewasanerr

c# - Entity Framework 迁移重命名表和列

我重命名了几个实体及其导航属性,并在EF5中生成了一个新的迁移。与EF迁移中的重命名一样,默认情况下它会删除对象并重新创建它们。这不是我想要的,所以我几乎不得不从头开始构建迁移文件。publicoverridevoidUp(){DropForeignKey("dbo.ReportSectionGroups","Report_Id","dbo.Reports");DropForeignKey("dbo.ReportSections","Group_Id","dbo.ReportSectionGroups");DropForeignKey("dbo.Editables","Section_

c# - Entity Framework 迁移重命名表和列

我重命名了几个实体及其导航属性,并在EF5中生成了一个新的迁移。与EF迁移中的重命名一样,默认情况下它会删除对象并重新创建它们。这不是我想要的,所以我几乎不得不从头开始构建迁移文件。publicoverridevoidUp(){DropForeignKey("dbo.ReportSectionGroups","Report_Id","dbo.Reports");DropForeignKey("dbo.ReportSections","Group_Id","dbo.ReportSectionGroups");DropForeignKey("dbo.Editables","Section_

c# - 无法将类型为 'System.DBNull' 的对象转换为类型 'System.String`

我的应用程序出现了上述错误。这是原始代码publicstringGetCustomerNumber(Guidid){stringaccountNumber=(string)DBSqlHelperFactory.ExecuteScalar(connectionStringSplendidmyApp,CommandType.StoredProcedure,"GetCustomerNumber",newSqlParameter("@id",id));returnaccountNumber.ToString();}我替换为publicstringGetCustomerNumber(Guidid