Я получаю эту ошибку в моем методе GetForumsByForumGroupID, где он выбирает объект Forum в моей записи Linq. У меня не было этой ошибки раньше, поэтому я не знаю, почему она у меня есть. Мне даже не нужен объект Forum, мне просто нужны свойства Title и ForumID, но я не знаю, как вернуть анонимный объект, например.
var forums = (from x in db.Forums select new {ForumID = x.ForumID, Title = x.Title}).ToList();
Ошибка здесь. возвращает выбранные форумы по выпадающему списку
public List<Forum> GetForumsByForumGroupID(int ForumGroupID)
{
using (CMSEntities db = new CMSEntities())
{
List<Forum> forums = (from x in db.Forums where x.ParentID == ForumGroupID select
new Forum(x.ForumID, "",DateTime.Now, x.Title, "", 0, x.Importance, false, "",
"", "", DateTime.Now, true, "", 0, "", DateTime.Now, "", 0, 0, "", 0)).ToList<Forum>();
return forums;
}
}
Markup:
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
DataSourceID="ObjectDataSource1" DataTextField="Key"
DataValueField="Value">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetDisplayForumGroups" TypeName="CMS.Framework.Forums">
</asp:ObjectDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource2">
<Columns>
<asp:BoundField DataField="ForumID" HeaderText="ForumID"
SortExpression="ForumID" />
<asp:BoundField DataField="AddedBy" HeaderText="AddedBy"
SortExpression="AddedBy" />
<asp:BoundField DataField="AddedDate" HeaderText="AddedDate"
SortExpression="AddedDate" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="ParentID" HeaderText="ParentID"
SortExpression="ParentID" />
<asp:BoundField DataField="Importance" HeaderText="Importance"
SortExpression="Importance" />
<asp:CheckBoxField DataField="Moderated" HeaderText="Moderated"
SortExpression="Moderated" />
<asp:BoundField DataField="Url" HeaderText="Url" SortExpression="Url" />
<asp:BoundField DataField="ImageUrl" HeaderText="ImageUrl"
SortExpression="ImageUrl" />
<asp:BoundField DataField="UpdatedBy" HeaderText="UpdatedBy"
SortExpression="UpdatedBy" />
<asp:BoundField DataField="UpdatedDate" HeaderText="UpdatedDate"
SortExpression="UpdatedDate" />
<asp:CheckBoxField DataField="Active" HeaderText="Active"
SortExpression="Active" />
<asp:BoundField DataField="ForumGroup" HeaderText="ForumGroup"
SortExpression="ForumGroup" />
<asp:BoundField DataField="ThreadCount" HeaderText="ThreadCount"
SortExpression="ThreadCount" />
<asp:BoundField DataField="LastPostBy" HeaderText="LastPostBy"
SortExpression="LastPostBy" />
<asp:BoundField DataField="LastPostDate" HeaderText="LastPostDate"
SortExpression="LastPostDate" />
<asp:BoundField DataField="LastPostTitle" HeaderText="LastPostTitle"
SortExpression="LastPostTitle" />
<asp:BoundField DataField="LastPostID" HeaderText="LastPostID"
SortExpression="LastPostID" />
<asp:BoundField DataField="ThreadID" HeaderText="ThreadID"
SortExpression="ThreadID" />
<asp:BoundField DataField="ThreadTitle" HeaderText="ThreadTitle"
SortExpression="ThreadTitle" />
<asp:BoundField DataField="ReplyCount" HeaderText="ReplyCount"
SortExpression="ReplyCount" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetForumsByForumGroupID" TypeName="CMS.Framework.Forums">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue"
Type="Int32" Name="ForumGroupID" />
</SelectParameters>
</asp:ObjectDataSource>
Обновлен:
public GetForumsByForumGroupID(int ForumGroupID)
{
using (CMSEntities db = new CMSEntities())
{
var forums = (from x in db.Forums where x.ParentID == ForumGroupID select
x).ToList();
return forums;
}
}
Не могу сделать это тоже
public List<Forum> GetForumsByForumGroupID(int ForumGroupID)
{
using (CMSEntities db = new CMSEntities())
{
List<Forum> formus = (from x in db.Forums where x.ParentID == ForumGroupID select
x).ToList<Forum>();
return forums;
}
}