Click here to Skip to main content
15,845,589 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: trying to call a WebApi method along with new Page when button clicked using jQuery Pin
Richard Deeming1-Aug-17 8:24
mveRichard Deeming1-Aug-17 8:24 
GeneralRe: trying to call a WebApi method along with new Page when button clicked using jQuery Pin
indian1431-Aug-17 14:23
indian1431-Aug-17 14:23 
QuestionI would like to develope new project from scratch. I would like to use ASP.NET MVC 5.0, EntityFramework and SQL Server. Pin
Lad Kunal30-Jul-17 21:14
Lad Kunal30-Jul-17 21:14 
AnswerRe: I would like to develope new project from scratch. I would like to use ASP.NET MVC 5.0, EntityFramework and SQL Server. Pin
Richard MacCutchan30-Jul-17 21:42
mveRichard MacCutchan30-Jul-17 21:42 
AnswerRe: I would like to develope new project from scratch. I would like to use ASP.NET MVC 5.0, EntityFramework and SQL Server. Pin
indian1432-Aug-17 7:57
indian1432-Aug-17 7:57 
QuestionError message: The operation cannot be completed because the DbContext has been disposed Pin
indian14327-Jul-17 12:39
indian14327-Jul-17 12:39 
AnswerRe: Error message: The operation cannot be completed because the DbContext has been disposed Pin
Richard Deeming28-Jul-17 2:31
mveRichard Deeming28-Jul-17 2:31 
AnswerRe: Error message: The operation cannot be completed because the DbContext has been disposed Pin
Nathan Minier28-Jul-17 2:36
professionalNathan Minier28-Jul-17 2:36 
Your WebAPI is attempting to serialize the object returned by your method, but the navigation properties point to the database connection built by the disposed connection.

There are many, many ways to skin this. The easiest (to me) is to locate the relationships in the Model that you do not want passed along with the basic call and decorate them with [JsonIgnore]. After doing that you can explicitly include them with the LINQ .Include(). You MUST have a reference to System.Data.Entity to use the strongly-typed extension of this method.

For example:
C#
public class FooBar
{
   ...
   [JsonIgnore]
   public virtual ICollection<Foo> Foos { get; set; }

   public virtual ICollection<Bar> Bars { get; set; }
}

Now your Get:
C#
using System.Data.Entity; //this has to be here to use the strongly-typed Include
...
public IEnumerable<FooBar> Get()
{
   using(var context = new MyDbContext()){
   {
      return context.FooBars.Include(x => x.Bars).ToArray();
   }
}


This will have the API respond to requests with all FooBars, with all associated Bars and no Foos. It's important to note that this will also need to be done with any other related models, so if Bar has relationship properties, you'll need to configure them for serialization.

By the way, using dynamic in a context where a strong type or generic will suffice is bad juju; it invites trouble.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli

QuestionUnable to use RequiredValidator control to validate RadioButtonList in Repeater? Pin
samflex26-Jul-17 15:25
samflex26-Jul-17 15:25 
AnswerRe: Unable to use RequiredValidator control to validate RadioButtonList in Repeater? Pin
F-ES Sitecore26-Jul-17 23:45
professionalF-ES Sitecore26-Jul-17 23:45 
GeneralRe: Unable to use RequiredValidator control to validate RadioButtonList in Repeater? (SOLVE) Pin
samflex27-Jul-17 4:05
samflex27-Jul-17 4:05 
QuestionFew questions about web api versioning in core Pin
Mou_kol26-Jul-17 2:38
Mou_kol26-Jul-17 2:38 
QuestionEnable/Disable div based on RadiobuttonList Pin
samflex25-Jul-17 6:41
samflex25-Jul-17 6:41 
AnswerRe: Enable/Disable div based on RadiobuttonList Pin
F-ES Sitecore25-Jul-17 7:30
professionalF-ES Sitecore25-Jul-17 7:30 
AnswerRe: Enable/Disable div based on RadiobuttonList Pin
Richard Deeming25-Jul-17 7:50
mveRichard Deeming25-Jul-17 7:50 
GeneralRe: Enable/Disable div based on RadiobuttonList (SOLVED) Pin
samflex25-Jul-17 10:32
samflex25-Jul-17 10:32 
QuestionVisual Studio & Asp.Net in Web Forms Bad Design view Pin
zequion23-Jul-17 3:23
professionalzequion23-Jul-17 3:23 
QuestionTable resizing in MVC bootstrap Pin
Member 1075459521-Jul-17 8:31
Member 1075459521-Jul-17 8:31 
AnswerRe: Table resizing in MVC Pin
Member 1075459527-Jul-17 11:44
Member 1075459527-Jul-17 11:44 
QuestionResponse.Cache, Code Location Pin
jkirkerx17-Jul-17 10:24
professionaljkirkerx17-Jul-17 10:24 
AnswerRe: Response.Cache, Code Location Pin
Richard Deeming17-Jul-17 11:09
mveRichard Deeming17-Jul-17 11:09 
GeneralRe: Response.Cache, Code Location Pin
jkirkerx18-Jul-17 8:38
professionaljkirkerx18-Jul-17 8:38 
QuestionUsing Visual Studio to debug iHTTPHandler routines Pin
Member 839420716-Jul-17 22:26
Member 839420716-Jul-17 22:26 
Questionwhat is default concurrent requests settings in IIS 8.5 Pin
bhavin chheda16-Jul-17 3:02
bhavin chheda16-Jul-17 3:02 
AnswerRe: what is default concurrent requests settings in IIS 8.5 Pin
Richard MacCutchan16-Jul-17 3:42
mveRichard MacCutchan16-Jul-17 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.