无法在 Linq 中将 byte[] 转换为二进制

发布于 2024-10-25 15:25:57 字数 3213 浏览 0 评论 0原文

我正在通过 ObservableCollection 进行 Linq 查询,但无法将二进制类型转换为 byte[]。

我的代码是这样的。

q1 = (from a in Helper.db.AccountStatement
                      join b in Helper.db.BankAccount on a.BankAccId equals b.BankAccId
                      join c in Helper.db.BankBranch on b.BankBranchId equals c.BankBranchId
                      join d in Helper.db.Bank on c.BankId equals d.BankId
                      where b.AccType == stracctype && b.UserId == intuserid && a.ActiveStatement == true && b.ActiveAccount == true
                      group new { b, d, a } by new { b.BankAccId, d.Name, b.AccNumber } into h
                      select new BankSummaryDataGrid
                      {
                          BankAccId = h.Key.BankAccId,
                          byteLogo = Convert.FromBase64String(d.VectorLogo.ToString().Replace("\"", "")),
                          BankName = h.Key.Name,
                          AccountNumber = h.Key.AccNumber,
                          ClosingBalance = ((h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strDr).Sum(p => p.a.TxnAmt) == null ? 0.0 : h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strDr).Sum(p => p.a.TxnAmt)) - (h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strCr).Sum(p => p.a.TxnAmt) == null ? 0.0 : h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strCr).Sum(p => p.a.TxnAmt)))
                      }).ToList();

BankSummaryDataGrid 是 ObservableCollection 的类。所以我收到这样的错误。

解析查询时出错。 [ 令牌行号 = 19,令牌行偏移 = 41,错误令牌 = MAX ]

byteLogo 是 byte[] 的类型。!

System.Data.SqlServerCe.SqlCeException 被捕获 消息=解析查询时出错。 [ 令牌行号 = 19,令牌行偏移 = 41,错误令牌 = MAX ] 源 = SQL Server Compact ADO.NET 数据提供程序 HResult=-2147217900 本机错误=25501 堆栈跟踪: 在 System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan() 在 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior 行为、String 方法、ResultSetOptions 选项) 在System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior行为) 在 System.Data.Common.DbCommand.ExecuteReader() 在 System.Data.Linq.SqlClient.SqlProvider.Execute(表达式查询、QueryInfo queryInfo、IObjectReaderFactory 工厂、Object[]parentArgs、Object[]userArgs、ICompiledSubQuery[]subQueries、ObjectlastResult) 在 System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(表达式查询、QueryInfo[] queryInfos、IObjectReaderFactory 工厂、Object[] userArguments、ICompiledSubQuery[] subQueries) 在 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询) 在 System.Data.Linq.DataQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() 在 System.Collections.Generic.List1..ctor(IEnumerable1 集合) 在 System.Linq.Enumerable.ToList[TSource](IEnumerable1 源) 位于 E:\工作文件夹 2011\MoneyCubePlus\Source\HMBL\TransactionManager\Transaction.cs 中的 HMBL.Bank.GetBankSummary(Int32 intuserid, String stracctype):第 993 行 内部异常:

谢谢...!!

I am working on Linq Query through the ObservableCollection, but I am not able to convert type binary to byte[].

my code is like this.

q1 = (from a in Helper.db.AccountStatement
                      join b in Helper.db.BankAccount on a.BankAccId equals b.BankAccId
                      join c in Helper.db.BankBranch on b.BankBranchId equals c.BankBranchId
                      join d in Helper.db.Bank on c.BankId equals d.BankId
                      where b.AccType == stracctype && b.UserId == intuserid && a.ActiveStatement == true && b.ActiveAccount == true
                      group new { b, d, a } by new { b.BankAccId, d.Name, b.AccNumber } into h
                      select new BankSummaryDataGrid
                      {
                          BankAccId = h.Key.BankAccId,
                          byteLogo = Convert.FromBase64String(d.VectorLogo.ToString().Replace("\"", "")),
                          BankName = h.Key.Name,
                          AccountNumber = h.Key.AccNumber,
                          ClosingBalance = ((h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strDr).Sum(p => p.a.TxnAmt) == null ? 0.0 : h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strDr).Sum(p => p.a.TxnAmt)) - (h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strCr).Sum(p => p.a.TxnAmt) == null ? 0.0 : h.Where(p => p.a.TxtType == HMBL.WealthManager.WMCoAEntities.clsTransactionType.strCr).Sum(p => p.a.TxnAmt)))
                      }).ToList();

BankSummaryDataGrid is the Class of ObservableCollection. so the I am getting error like this.

There was an error parsing the query. [ Token line number = 19,Token line offset = 41,Token in error = MAX ]

byteLogo is the type of the byte[].!

System.Data.SqlServerCe.SqlCeException was caught
Message=There was an error parsing the query. [ Token line number = 19,Token line offset = 41,Token in error = MAX ]
Source=SQL Server Compact ADO.NET Data Provider
HResult=-2147217900
NativeError=25501
StackTrace:
at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source)
at HMBL.Bank.GetBankSummary(Int32 intuserid, String stracctype) in E:\Working Folder 2011\MoneyCubePlus\Source\HMBL\TransactionManager\Transaction.cs:line 993
InnerException:

Thanks...!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

探春 2024-11-01 15:25:57

我相信问题是您正在使用 linq to sql 不支持的方法,

我会将其更改

byteLogo = Convert.FromBase64String(d.VectorLogo.ToString().Replace("\"", "")),

vectorLogo= d.VectorLogo

然后一旦您在本地拥有列表,我将使用 linq to object 将其转换为字节数组

I believe the problem is that you are using methods that are not supported by linq to sql

I would change this

byteLogo = Convert.FromBase64String(d.VectorLogo.ToString().Replace("\"", "")),

To

vectorLogo= d.VectorLogo

And then once you have the list locally I would convert it to your byte array with linq to objects

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文