Reputation: 25
Is there a way to only select one table with any references?
Because with my current code the DataContext
returns a Types
object. But LINQ adds a property on it called campaign
and in that property there are all other references. So i takes forever when i am requesting data from my restapi controller, cause it needs to load all references. But i only want the Table i was asking for.
Current code:
[HttpGet]
[Route("Typs")]
public IHttpActionResult Typs()
{
crmDataContext crmDC = new crmDataContext();
jsSettings = ReferenceLoopHandling.Ignore;
return Json(crmDC.Typs), jsSettings);
}
Typs propertys that i have defined in my database
public class Typs
{
public int id;
public string text;
}
Typs propertys that linq made for my c# code
public class Typs
{
public int id;
public string text;
public campaign campaign;
}
Upvotes: 2
Views: 682
Reputation: 30545
It does'nt make sense. You must used Include() or explicit loading .Collection(p => p.Posts).Load();
otherwise related entities are not loaded.
Futhermore you dont need to add ReferenceLoopHandling.Ignore;
if you are not goind to load related entities which in turns references the table itself.
Upvotes: 1