我有兩個表使用數組中的值來查詢數據庫。郵政表和關注表。發佈表具有用戶的所有帖子,並且關注表具有用戶跟隨的用戶列表。無法使用LINQ
郵政表
PostID UserID Post
1 2 TextOne
2 1 TextTwo
3 1 Text3
4 2 Text4
按照表
ID Following FollowedBy
1 2 1
2 3 1
而且我有一個列表視圖。
<ItemTemplate >
Post:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Post") %>' />
<br />
UserID:
<asp:Label ID="Label2" runat="server" Text='<%# Eval("UserID") %>' />
<br />
</ItemTemplate>
我想顯示用戶以及他關注的人的帖子。我寫了下面的代碼。
int UserId = Convert.ToInt32(Session["User"]);
int[] OthersPosts = (from s in Data.Follow where s.FollowedBy == UserId) select s.Following1).ToArray();
foreach (int post in OthersPosts)
{
var DisplayPost = (from s in Data.Posts where s.UserID == post && s.UserID == UserId) select s).ToList();
ListViewPostTable.DataSourceID = "";
ListViewPostTable.DataSource = DisplayPost;
ListViewPostTable.DataBind();
}
但是沒有數據顯示在ListView
上?
我在DisplayPost
變量檢查值的監視窗口,它說:Enumeration yielded no results
。
什麼在OthersPosts陣列的返回值? –
的用戶ID的人,隨後的的「用戶ID」 –
我認爲你有正確的查詢可能是這樣的: VAR DisplayPost =(從s在Data.Posts其中s.PostID ==後&& s.UserID ==用戶ID )select s).ToList(); –