[英]Unable to cast object of type 'System.Int64' to type 'System.Int32'
Getting the error when asking for equal type of string in 在请求相等类型的字符串时出现错误
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t =>
t.ToMemberMobilePhone.ToUpperInvariant().Equals(mobilePhone.ToUpperInvariant()));
public async Task<bool> UpdateOrderTransferToMemberId(string mobilePhone, string memberid)
{
if (mobilePhone != null)
{
using (var context = ContextManager.ClubContext())
{
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t => t.ToMemberMobilePhone.ToUpperInvariant().Equals(mobilePhone.ToUpperInvariant()));
if (orderTransferFromDb != null)
{
context.Attach(orderTransferFromDb);
orderTransferFromDb.ToMemberId = memberid;
await context.SaveChangesAsync();
}
return true;
}
}
throw new Exception("MobilePhone is null. (UpdteOrderTransferByEmail)");
}
The arguments are both string
, and in SQL Server nvarchar(13)
参数都是
string
,在SQL Server中为nvarchar(13)
What can cause it? 是什么原因造成的?
There's nothing wrong with your code. 您的代码没有错。 You need to double check your context whether is mapped correctly with your object.
您需要仔细检查上下文是否与对象正确映射。
To Compare string without case, use this 要比较不区分大小写的字符串,请使用此
var orderTransferFromDb = await context.OrderTransfer.FirstOrDefaultAsync(t => string.Equals(t.ToMemberMobilePhone, mobilePhone, StringComparison.OrdinalIgnoreCase));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.