English 中文(简体)
LINQ选择语句
原标题:LINQ Select Statement
  • 时间:2010-03-05 21:10:54
  •  标签:
  • linq
  • select

I m developing a web application myself to follow some rssfeeds. My purpose is just learning some ajax and i send data from server to client side in JSON format. I use LINQ for querying data and JSON .NET API for object to string Serialization in the server side. The problem is that because of there exists foreign keys between my tables linq objects include references to the same table and JSON .NET API throws self referencing object error.

DAL.BlogReaderDBDataContext db = new DAL.BlogReaderDBDataContext();

            var list = from p in db.Lookup_RSSFeedCategories
                       select new
                       {
                           CreateDate = p.CreateDate.ToLongDateString(),
                           p.Description,
                           p.RSSFeeds,
                           p.RSSFeedCategoryId
                       };

            return Newtonsoft.Json.JsonConvert.SerializeObject(list);

我认为,这个问题在p.RSSFeeds上,这里的RSSFeeds是RSSFeed物体清单。 我只想选择这份名单的描述和RSSFeedID领域——每个物体SSFeed物体——如何做到这一点?

谢谢... (xiè xiè...)

最佳回答

问题解决了。

p.RSSFeeds.Select(x => new {x.Description,x.RSSFeedID}),
问题回答

暂无回答




相关问题
IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....

linq query for tag system - search for multiple tags

I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

How to filter duplicate list items

i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...

C# Grouping/Sorting a Generic List<> using LINQ

Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...

热门标签