Q:

Stop loading of self referencing entities in many to many

I have a many to many relationship in entity framework and its causing me serialisation problems as its looping infinity (using newtonsoft) I get the : Self referencing loop detected error:
I tried the options setting from Self referencing loop Entity FrameWork
 config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling 
= Newtonsoft.Json.ReferenceLoopHandling.Ignore; 

But it doesnt fix it. My classes look like:
public class Job
{
    public int Id { get; set; }
    public string Title { get; set; }
    public virtual ICollection<Tag> Tags { get; set; }
}

public class Tag
{
    public int Id { get; set; }
    public string Title { get; set; }
    public ICollection<Job> Jobs { get; set; }
}

So in .net when I do a search on jobs can I tell it to only include tags and not jobs again after that? Ie with:
   // How to not include jobs in tags object?
   var jobs = context.Job.Include(x => x.Tags);

A:

The simple answer is "don't send entities to the client, use a view model." 
If all your client cares about is a Job and a list of it's tags:
[Serializable]
public class JobViewModel
{
    public int JobId { get; set;}
    public string Title { get; set; } 
    public List<TagViewModel> Tags { get; set; } = new List<TagViewModel>();
}
[Serializable]
public class TagViewModel
{
    public int TagId { get; set; }
    public string Title { get; set; }
}

Then, selecting all jobs and their tags: (ideally this should have a Where clause or pagination, but for example's sake)
var jobs = context.Jobs.Select(j => new JobViewModel
{
    JobId = j.JobId,
    Title = j.Title,
    Tags = j.Tags.Select(t => new TagViewModel
    {
        TagId = t.TagId,
        Title = t.Title
    }).ToList()
}).ToList();

You can avoid this manual casting using AutoMapper and it's ProjectTo<T> method which integrates nicely with EF's IQueryable based methods.
var jobs = context.Jobs
    .ProjectTo<JobViewModel>()
    .ToList();

Why?

Avoid cyclic reference serialization issues.
Optimize queries sent to the database to only pull back the fields needed.
Reduce memory usage on the servers and client.
Reduce the amount of data sent over the wire between servers, and to the client.
Avoid sending more data to the client than is needed. (exposing entire domain model otherwise not shown)
Avoid the risk of accepting entities back from the client, attaching, and saving changes that were not intended. (debugger manually altering fields or associated entities)

