简体   繁体   中英

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)");     
}

订单转移模型

SQL

The arguments are both string , and in 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM