【发布时间】:2016-02-16 15:11:28
【问题描述】:
我想通过标签搜索帖子,例如,当我在搜索框中写“ASP”时,我将搜索它们具有相同标签的帖子并将它们作为帖子列表返回...
这也是我的书课:
[Table("Book")]
public partial class Book
{
[Key]
public int Book_id { get; set; }
[Required]
[Display(Name ="User Name")]
[StringLength(128)]
public string User_ID { get; set; }
[Required]
[Display(Name = "Title Name")]
[StringLength(70,MinimumLength =3)]
public string Book_name { get; set; }
[Display(Name = "Edition")]
[Range(1, 20)]
public int Edition { get; set; }
[Display(Name = "Category Name")]
public int Category_id { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[Display(Name = "Publish Date")]
public DateTime Publish_date { get; set; }
[StringLength(50)]
[Display(Name = "Author Name")]
public string Author_name { get; set; }
[StringLength(128)]
[Display(Name = "Cover Image")]
public string Book_Image { get; set; }
[StringLength(128,MinimumLength =8)]
[Url]
[Display(Name = "Download Link")]
public string Download_Link { get; set; }
[StringLength(250)]
[Display(Name = "Upload Pdf")]
public string pdf_file { get; set; }
[AllowHtml]
[Column(TypeName = "text")]
[Display(Name = "Description")]
public string Book_Description { get; set; }
public int View_Count { set; get; }
[StringLength(250,MinimumLength =2,ErrorMessage ="Min Tags Input lenght is 2 char")]
[Display(Name = "Tags")]
public virtual string TagsListing { get; set; }
public virtual IList<Tag> Tags
{ get; set; }
public virtual AspNetUser AspNetUser { get; set; }
public virtual Category Category { get; set; }
}
还有标签类:
public class Tag
{
public virtual int Id
{ get; set; }
public virtual string Name
{ get; set; }
public virtual string UrlSlug
{ get; set; }
public virtual string Description
{ get; set; }
public virtual IList<Book> Books
{ get; set; }
}
我只是想看看访问者搜索的搜索词是否可以在标签表中找到,并返回与相同标签相关的书籍列表..
谢谢
【问题讨论】:
-
类似
db.Tags.Where(t => t.Name.Equals(input)).SelectMany(t => t.Books).Distinct()的东西?这里的任何人都不可能知道您将使用什么特定代码,因为您没有显示有关您的数据访问代码的任何信息。 -
@David,我更新了我的问题并添加了我的书和标签类
标签: asp.net asp.net-mvc asp.net-mvc-4 razor