当我尝试按字段名称查找记录时,uuid
出现以下错误:
{“无法将类型为“System.Data.Entity.Infrastruct.DbQuery`1[SyncBank.Models.XeroBankAccount]”的对象转换为类型为“SyncBank.Models.XeroBankAccount”
public XeroBankAccount FindAccountByUuid(String uuid)
{
try
{
using (SyncBankDbContext dbContext = new SyncBankDbContext())
{
string tempUuid = uuid;
var result = (XeroBankAccount) dbContext.XeroBankAccounts.Where(x => x.AccountUuid == tempUuid);
return result;
}
}
catch (Exception e)
{
string errorMessage = e.Message;
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
{"Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[SyncBank.Models.XeroBankAccount]' to type 'SyncBank.Models.XeroBankAccount'."}
Run Code Online (Sandbox Code Playgroud)
XeroBankAccount.cs:
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using SyncBank.Xero;
namespace SyncBank.Models
{
[Serializable]
[Table("xero_bank_account")]
public class XeroBankAccount
{
[Key]
[Column("id")]
public int …
Run Code Online (Sandbox Code Playgroud)