【发布时间】:2011-04-28 14:44:21
【问题描述】:
我有 NHibernate IList。我想转换为列表。请帮帮我。
这是我的代码
IList<Tag> list = Tag.GetAll();
我想把它转换成列表
public class CategoryTag
{
public int ID { get; set; }
public string TagName { get; set; }
public CategoryTag()
{
}
public List<CategoryTag> GetCategoryTagList()
{
IList<Tag> list = Tag.GetAll();
// How do I return Tag as List?
return tagList;
}
}
更新
我想更新我的问题,因为我的问题没有得到很好的解释。
这是我将其传递给 jQuery UI 自动完成的代码:
[WebMethod]
public IList<Tag> FetchTagList(string tag)
{
var ctag = new List<Tag>(Tag.GetAll())
.Where(m => m.TagName.ToLower().StartsWith(tag.ToLower()));
return ctag.ToList();
}
我收到以下错误:
无法序列化接口 System.Collections.Generic.IList`1[[QuestionCenter.Domain.Tag, QuestionCenter.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]。
将我的 IList 传递给 JSON 的任何解决方案都会对我有所帮助。谢谢。
【问题讨论】:
-
为什么需要列表?返回 IList 实际上是首选方法,因为它不是列表数据结构的特定实现
-
是的,但我想通过 webservice 将它传递给 JSON。
标签: c# nhibernate list ilist