溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何解決LINQ泛型數(shù)據(jù)集問題

發(fā)布時(shí)間:2021-12-02 09:38:08 來源:億速云 閱讀:89 作者:小新 欄目:編程語言

這篇文章主要為大家展示了“如何解決LINQ泛型數(shù)據(jù)集問題”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何解決LINQ泛型數(shù)據(jù)集問題”這篇文章吧。

查詢是一種從數(shù)據(jù)源檢索數(shù)據(jù)的表達(dá)式。查詢用專用查詢語言表示。隨著時(shí)間的推移,人們已經(jīng)為不同類型的數(shù)據(jù)源開發(fā)了不同的語言,例如,用于關(guān)系數(shù)據(jù)庫的 SQL 和用于 XML 的 XQuery。這使應(yīng)用程序開發(fā)人員必須針對(duì)所支持的每種數(shù)據(jù)源或數(shù)據(jù)格式而學(xué)習(xí)新的查詢語言。

語言集成查詢 (LINQ) 通過提供一種跨各種數(shù)據(jù)源和數(shù)據(jù)格式使用數(shù)據(jù)的一致模型,簡化了這一情況。在 LINQ 查詢中,始終會(huì)用到對(duì)象。在查詢和轉(zhuǎn)換 XML 文檔、SQL 數(shù)據(jù)庫、ADO.NET 數(shù)據(jù)集和實(shí)體、.NET Framework 集合中的數(shù)據(jù)以及具有相應(yīng)的 LINQ 提供程序的任何其他源或格式的數(shù)據(jù)時(shí),都會(huì)使用相同的基本編碼模式。

定義一個(gè)返回LINQ泛型數(shù)據(jù)集代碼:

  1. using System;  

  2. using System.Collections.Generic;  

  3.  

  4. namespace BlueCube.BusinessLogic  

  5. {  

  6.  

  7. /// <summary> 

  8. /// Encapsulates execution result contains whether the 
    execution is successful and what messages the invoker will receive.  

  9. /// </summary> 

  10. public class ExecutionResult<T> 

  11. {  

  12. /// <summary> 

  13. /// True as execution is successful. False as failed.  

  14. /// </summary> 

  15. public bool Success  

  16. {  

  17. get;  

  18. set;  

  19. }  

  20.  

  21. private List<string> _Messages = null;  

  22.  

  23. /// <summary> 

  24. /// Stores message list  

  25. /// </summary> 

  26. public List<string> Messages  

  27. {  

  28. get  

  29. {  

  30. // Initialize message list if it is null  

  31. if (_Messages == null)  

  32. {  

  33. _Messages = new List<string>();   

  34. }  

  35. return _Messages;  

  36. }  

  37.  

  38. set  

  39. {  

  40. // Clear existed message list then add new list from value  

  41. if (_Messages != null)  

  42. {  

  43. _Messages.Clear();  

  44. foreach (string message in value)  

  45. {  

  46. _Messages.Add(message);  

  47. }  

  48. }  

  49. else  

  50. {  

  51. _Messages = value;  

  52. }  

  53. }  

  54. }  

  55.  

  56. /// <summary> 

  57. /// Encapsulates the value if there is any return value during execution  

  58. /// </summary> 

  59. public T ReturnValue  

  60. {  

  61. get;  

  62. set;  

  63. }  

  64. }  

以上是“如何解決LINQ泛型數(shù)據(jù)集問題”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI