开发者

Query return object by String Content

I try to return Object by content which have string type:

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;
}

I call the function above by:

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

and get:

System.Data.EntityCommandExecutionException: "An error occurred while executing the command definition. See the inner exception for details."

important to note: when I do this function whis Int Type String there is no problem.

any idea?


LINQ does not allow you to compare database fields with the text datatype using =. For some ideas on what you can do about it, look at this SO question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜