【问题标题】:C# Linq error msg "could not find an implementation of the query pattern for source type 'double?'. 'Select' not foundC# Linq 错误消息“找不到源类型“双精度”的查询模式的实现。找不到“选择”
【发布时间】:2013-05-30 01:14:56
【问题描述】:

我正在尝试设置一个简单的银行应用程序,该应用程序可以在用户存款时增加利息。我在接受存款金额的网络表单上有一个文本框,当点击“提交”时,将进行计算。但是我得到“找不到源类型'double'的查询模式的实现?'。找不到'选择'。”我的代码中的消息。余额被宣布为双?在 Accounts 类中。我已经看到的很多解决方案都是在顶部添加 using System.Linq 命名空间,但我已经这样做了。

public void GetInterest()
        {

            var db = new CelticSavingsBank.Classes.Accounts(); 

            var myBalance = from a in db.Balance
                             select a;
                db.Balance = myBalance + (myBalance * 0.03);    

        }

        protected void depositButton_Click(object sender, EventArgs e)
        {
            GetInterest();
        }

【问题讨论】:

  • 不清楚您的查询是什么意思,但是db.BalanceNullable<double>,因此您不能使用 linq 对其进行查询。
  • 您的查询没有意义。 from x in y select x 不是读取数据库的魔法咒语。

标签: c# asp.net linq


【解决方案1】:

db.Balancedouble?

除非你有一组非常奇怪的扩展方法,否则你只能在 collection 上运行 LINQ 查询;即IEnumerable<T>

【讨论】:

  • pedantry IEnumerable<T>IQueryable<T>
  • @P.Brian.Mackey: 超级学究 IQueryable<T>实现IEnumerable<T>
  • 还有对ParallelQuery<T>的LINQ支持的内置扩展方法(是的,它也实现了IEnumerable<T>,但是像IQueryable<T>,除非你有很好的理由,你应该' t 使用Enumerable 扩展)
猜你喜欢
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多