gpt4 book ai didi

c# - 系统.Data.EntitySqlException : The argument types 'Edm.String' and 'Edm.Int32' are incompatible for this operation

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:15 24 4
gpt4 key购买 nike

我不得不更改查询中一个参数的数据类型,现在我收到了此消息标题中概述的错误消息。我一直试图弄清楚问题出在哪里,我唯一能想到的是,由于查询的一个参数是一个数字,另一个是字符串,所以这是导致问题的原因。不幸的是,我对 Entity Framework 还很陌生,不知道如何调整我的查询来解决这个问题

这是我正在使用的查询:

var Item = (DataContextFactory.GetDataContext().Items.Include("Category")
.Where("it.CategoryID == " + categoryId + " && it.itemID == " +
itemId)).SingleOrDefault();

最佳答案

如果一个是字符串你忘了''

试试这个:(我不知道哪个是字符串。在这个例子中 categoryId 是字符串)

.Where(string.Format("it.CategoryID = '{0}' and it.itemID = {1}", categoryId, itemId))

关于c# - 系统.Data.EntitySqlException : The argument types 'Edm.String' and 'Edm.Int32' are incompatible for this operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20202690/

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