我有课:
public class FeedData
{
private List<FeedItem> _Items = new List<FeedItem>();
public List<FeedItem> Items
{
get
{
return this._Items;
}
}
}
public class FeedDataSource
{
private ObservableCollection<FeedData> _Feeds = new ObservableCollection<FeedData>();
public ObservableCollection<FeedData> Feeds
{
get
{
return this._Feeds;
}
}
}
我想让我的代码更小,所以我尝试使用LINQ
,但我只是不知道如何做到这一点。这是我的代码
private static FeedData GetFeedFromDatabase(string feedLink)
{
FeedData feedData = new FeedData();
using (var db = new SQLiteConnection(Application.Current.Resources["DbPath"].ToString()))
{
var matches = db.Table<FeedData>().Where(feed => feed.Link.Equals(feedLink));
if (matches.Any())
{
feedData = matches.Single();
feedData.Items.AddRange(
db.Table<FeedItem>().
Where(item => item.FeedId.Equals(feedData.Id))
);
}
}
return feedData;
}
我不想使用 AddRange,我想用尽可能少的LINQ
表达式从FeedData
表和FeedItem
表中获取数据。是否可以?