联接表我的应用程序的结构为:ASP.NET MVC - 使用LINQ
namespace DomainModel.Abstract
{
public interface IContentItemsRepository
{
IQueryable<Content> ContentItems { get; }
IQueryable<Category> Categories { get; }
IQueryable<ContentCategory> ContentCategories { get; }
}
}
namespace DomainModel.Entities
{
[Table(Name = "Content")]
public class Content
{
[Column(IsPrimaryKey = true,
IsDbGenerated = true,
AutoSync = AutoSync.OnInsert)]
public int content_id { get; set; }
[Column]
public string type { get; set; } // article, video, recipe, tool
[Column]
public string title { get; set; }
...
namespace DomainModel.Entities
{
[Table(Name = "Content_Categories")]
public class ContentCategory
{
[Column(IsPrimaryKey = true,
IsDbGenerated = true,
AutoSync = AutoSync.OnInsert)]
public int content_category_id { get; set; }
[Column]
public int content_id { get; set; }
[Column]
public int category_id { get; set; }
...
namespace DomainModel.Entities
{
[Table(Name = "Categories")]
public class Category
{
[Column(IsPrimaryKey = true,
IsDbGenerated = true,
AutoSync = AutoSync.OnInsert)]
public int category_id { get; set; }
[Column]
public string category_name { get; set; }
[Column]
public string type { get; set; } //recipe,tool,other
[Column]
public int ordering { get; set; }
...
我可以这样做:
var articlesInCategory = _contentRepository.ContentItems
.Where(x => x.type == "article");
,并得到的文章列表。没问题。
但是,我现在需要根据类别选择内容。所以,我需要将Content to ContentCategory加入到Category中。
我不知道如何做到这一点。任何帮助都感激不尽。
谢谢。
编辑:
我想我的问题的一部分是,我甚至不知道该怎么称呼我在做什么,所以很难寻找这一点。我甚至在做LINQ to SQL,或LINQ to Entities,还是LINQ to Objects?
不是真正的mvc问题。你也应该添加一个linq-to-sql标签。 – 2009-11-18 22:55:16