无法在 Linq 中将 byte[] 转换为二进制
我正在通过 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.DataQuery
1.System.Collections.Generic.IEnumerable
1..ctor(IEnumerable.GetEnumerator() 在 System.Collections.Generic.List 1 集合) 在 System.Linq.Enumerable.ToList[TSource](IEnumerable
1 源) 位于 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()
1..ctor(IEnumerable
at System.Collections.Generic.List1 collection)
1 source)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
at HMBL.Bank.GetBankSummary(Int32 intuserid, String stracctype) in E:\Working Folder 2011\MoneyCubePlus\Source\HMBL\TransactionManager\Transaction.cs:line 993
InnerException:
Thanks...!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题是您正在使用 linq to sql 不支持的方法,
我会将其更改
为
然后一旦您在本地拥有列表,我将使用 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
To
And then once you have the list locally I would convert it to your byte array with linq to objects