c# - Entity Framework Query for Multiple Tag Cloud related Posts -
if have model classes
[table("mtag")] public class tag { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int tagid { get; set; } public string taglabel { get; set; } public virtual icollection<tagref> reftags { get; set; } } [table("tagref")] public class tagref { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int tagrefid { get; set; } public virtual tag tag { get; set; } public virtual icollection<post> posts { get; set; } } [table("post")] public class post { [key] [databasegeneratedattribute(databasegeneratedoption.identity)] public int postid { get; set; } public userprofile user { get; set; } public string title { get; set; } public string description { get; set; } public string postguid { get; set; } public string make { get; set; } public string model { get; set; } public virtual icollection<mtagref> tags { get; set; } public string imagefilename { get; set; } public int price { get; set; } public int imagewidth { get; set; } public int imageheight { get; set; } } what possible queries select matching posts? can please give hint if have tags car, mobile how setup query?
you have tags car,mobile,vehicles,electronics , ... .
when add post add tag it.like site(stackoverflow) when add question add tags too. want select post sepecified tags.
the below method return post have tags:
public static iqueryable<post> postswithtags(list<int> tagids) { context c = new context(); var query = (from group in c.tagrefs.groupby(g => g.tagid) let grouptags = group.select(g => g.tagid) tagids.all(gt => grouptags.contains(gt)) select group.select(g => g.post).firstordefault()); return query ; }
Comments
Post a Comment