0
A
回答
1
使用Select擴展方法,以便直接創建匿名類型對象,而不是將它們分配給通用對象類的對象。然後您可以根據需要引用該對象的屬性。
IList<User> us = new UserRepository().Getuser(Name.ToUpper(),
UserName.ToUpper(),
UserCertNumber.ToUpper(),
Date.ToUpper(),
UserType.ToUpper(),
Company.ToUpper(),
PageNumber,
Orderby,
SearchALL.ToUpper(),
PrintAllPages.ToUpper());
var users = us.Select(u => new
{
Id = u[i].UserId,
Title = u[i].Title,
FirstName = u[i].FirstName,
LastName = u[i].LastName,
Privileges = (from apps in u[i].UserPrivileges select new { PrivilegeId = apps.Privilege.PrivilegeId, PrivilegeName = apps.Privilege.Name, DeactiveDate = apps.DeactiveDate }),
Status = (from status in u[i].UserStatus select new { StatusId = status.Status.StatusId, StatusName = status.Status.StatusName, DeactiveDate = status.DeactiveDate }),
ActiveDate = u[i].ActiveDate,
UserName = u[i].Email,
UserCN = (from cert in u[i].UserCertificates select new { CertificateNumber = cert.CertificateNumber, DeactiveDate = cert.DeactiveDate }),
Company = u[i].Company.Name
});
string x = "";
string y = "";
var report = users;
foreach (var r in report)
{
var company = r.Company; // example
...
}
編輯:BTW,是有一些原因,你是將所有這些參數爲大寫,而不是簡單地做不變的情況下,在比較你的倉庫?
0
你這樣做的方式是創建一個匿名類型。
創建一個包含這些屬性的類。另一種方法是將報表讀取到循環中。
+0
由tvanfosson解決方案爲我工作。謝謝您的回答。由tvanfosson爲我工作的 – bluwater2001 2010-05-11 21:20:20
0
object o = new { Name = "string" };
Console.WriteLine(o.GetType().GetProperty("Name").GetValue(o, null));
但這並不是真正推薦的做法。我將爲此創建標準數據傳輸類。
+0
解決方案。謝謝您的回答。 – bluwater2001 2010-05-11 21:20:41
0
只是增加tvanfosson解決方案:
如果我們想獲得我們做PrivilegeName:
foreach (var r in report)
{
x = r.FirstName; // example
foreach (var s in r.Privileges)
{
y = s.PrivilegeName; //Example
}
}
相關問題
- 1. ASP.NET從數據庫讀取數據
- 2. ASP.NET MVC ActionResult不從Ajax請求讀取json數據
- 3. 從C#讀取Excel數據#
- 4. 如何從Asp.net MVC中的表讀取發佈數據?
- 5. C# - DataGridView - 從另一個數據庫表中讀取一列嗎?
- 6. ASP.net Oracle數據讀取器在C#
- 7. 從一個數據塊讀取BLOB到另一個數據庫
- 8. 從BaseDataBoundControl.DataSource(ASP.NET GridView)讀取數據
- 9. 從asp.net平板文件讀取數據
- 10. C++從一個文件(包含空格)逐行讀取數據
- 11. 從一個表讀取數據到另一個基於Like「row_value」
- 12. $ .getJSON返回「未定義」的值,數據讀取[object Object]
- 13. 從一個表中讀取數據並使用它從另一個表中讀取數據
- 14. Url action null object asp.net mvc
- 15. 從asp.net輸入數據mvc
- 16. ASP.Net MVC 2 partialview讀取URL
- 17. 緩存一個數據列表asp.net c#
- 18. 取從Object類型C#
- 19. C#從GRIDVIEW讀取數據串
- 20. WPF,從C#中的XmlDataProvider讀取數據#
- 21. 從Excel首頁讀取數據 - C#
- 22. C#:從txt文件讀取數據
- 23. 使用C#從USB讀取數據?
- 24. C#:從xls文檔讀取數據
- 25. 使用C#從網站讀取數據
- 26. 從Access數據庫讀取c#
- 27. 從文件中讀取數據C
- 28. 從C++ dll讀取矢量數據?
- 29. 讀取數據從XLSX在C#
- 30. 從C++中的磁盤讀取數據
我的朋友你是AWESOME.AWESOME..and真棒。第一杆就像冠軍一樣。謝謝TON :) :) – bluwater2001 2010-05-11 21:18:57