Home > Net >  Returns an entity ExecuteQuery
Returns an entity ExecuteQuery

Time:09-26

///& lt; Summary>
///query whether there is any article
///& lt;/summary>
///& lt; Param name="id" & gt;
///& lt; Returns>
Public static Models. Dw GetNowenid2 (int wenid)
{
Using (yun udc=new yun ()) {

String strSql="SELECT wen. Id, wen. Dianjishu, wen, shijian, wen. Tupian, wen. Biaoti, wen. Xiazaidizhi, wen. Jianjie, wen. Neirong, [user]. Touxiang, [user]. Weixin, [user]. Qq, [user]. Ming, xiaolei. Id as id2, xiaolei. Ming as ming2 FROM (wen INNER JOIN [user] ON wen. The userid=[user]. Id) INNER JOIN xiaolei ON wen. Xiaoleiid=xiaolei. Id where wen. Id=" + wenid;

Var query=udc. ExecuteQuery (strSql);


Return (dw) Models. The query;

}

}

Compiled by the preview but is wrong
Unable to type into "OneTimeEnumerable ` 1 [Models. The dw]" the object of cast to type "Models. The dw,"
Note: during the execution of the current Web request, an unhandled exception, please check the stack trace, to learn about the errors and mistakes in the code of the source of detailed information,


ExecuteQuery returns seems to be a table but I only want one, and how to change


CodePudding user response:

Var query=udc. ExecuteQuery (strSql). The First ();

CodePudding user response:

https://docs.microsoft.com/zh-cn/dotnet/api/system.data.linq.datacontext.executequery? View=netframework 4.8
https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.firstordefault? View=netframework 4.8 # System_Linq_Enumerable_FirstOrDefault__1_System_Collections_Generic_IEnumerable___0__System_Func___0_System_Boolean__
  •  Tags:  
  • LINQ
  • Related