Linq2Sql Many:Many question, How would you do this?

Question!

I know many:many isn't supported in Linq2Sql but I am working on a workaround

I am working with my little SO clone and I have a table with Questions and a table with Tags and a linking table QuestionTag so I have a classic many:many relationship between Questions and Tags.

To display the list of Questions on the front page I have this class I want to fill up from a Linq2Sql query

public class ListQuestion
{
   public int QuestionID { get; set; }
   public string Title{ get; set; }
   public IEnumerable<Tag> Tags { get; set; }
}


public IEnumerable<ListQuestion> GetQuestions()
{
   from q in Questions
   .................
   select new ListQuestion{ ... }
}

The problem is how should I fill up the Tag collection. I found out this isn't possible to do in 1 single query so I have divided this into 2 queries, 1 to get the questions and 1 to get the tags and later try to join them. I know many:many is supported in Entity framework so how do they do it? How would you do this? Any alternative approach? The query should of course be efficient.

By : terjetyl


Answers

This may work for your case;

from q in Questions
select new ListQuestion 
{ 
  Tags = q.QuestionTags.Select(qt => qt.Tag),
  QuestionId = q.ID,
  Title = q.Title
}


You may not have permission to set the objectClass attribute. See whether you can attach the auxiliary class after creation, through ADSI Edit. If you can't, fix the permissions first (check the Properties tab in the Advanced view of Security settings)

I could attach this specific class right now, onto a organizationalUnit object, as a domain admin; so in principle, this is possible.



You're using utf8_encode($file), fine, but is PHP returning the content type as UTF-8 as well? Can you check the Content-Type header returned by your PHP page? You should particularly look at the charset field to make sure you have something like this:

Content-Type: text/html; charset=utf-8

I can see how a browser could be displaying the character correctly while .NET (rightfully or wrongfully) fails. Browsers usually try to be as robust and forgiving as possible. The browser you're using might be inferring the actual character encoding from the character sequences.



This video can help you solving your question :)
By: admin