【问题标题】:Query return object by String Content按字符串内容查询返回对象
【发布时间】:2011-08-16 00:53:21
【问题描述】:

我尝试按字符串类型的内容返回对象:

public ObjectQuery<question> getQuestionByContent(String content)
{
    DemoDBEntities _context = new DemoDBEntities();
    var x = _context.question.Where(p => p.q_content == content);
    Debug.WriteLine(((ObjectQuery)x).ToTraceString());
    return (ObjectQuery<question>)x;
}

我通过以下方式调用上面的函数:

public question BS_GetQuestionByContent(String content)
{
    DB_Implementation _dal = new DB_Implementation();
    return _dal.getQuestionByContent(content).SingleOrDefault<question>();
}

得到:

System.Data.EntityCommandExecutionException:“发生错误时 执行命令定义。请参阅内部异常 详情。”

需要注意的重要事项: 当我使用 Int Type String 执行此功能时,没有问题。

有什么想法吗?

【问题讨论】:

  • 什么是内部异常?
  • 内部异常: 说明:当前web请求执行过程中出现未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]:执行命令定义时出错。有关详细信息,请参阅内部异常。
  • 在你的数据库中,q_content是什么类型的?

标签: asp.net c#-4.0


【解决方案1】:

LINQ 不允许您使用 = 将数据库字段与文本数据类型进行比较。有关您可以做些什么的一些想法,请查看this SO question.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 2016-08-27
    • 2015-09-17
    相关资源
    最近更新 更多