public JsonResult getProjects() { bool proxyCreation = dc.Configuration.ProxyCreationEnabled; try { //set ProxyCreation to false dc.Configuration.ProxyCreationEnabled = false; var projects = dc.Projects.Include(p => p.ProjectType); return Json(projects.ToList(), "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(ex.Message); } finally { //restore ProxyCreation to its original state dc.Configuration.ProxyCreationEnabled = proxyCreation; } }
public partial class Project { public int ProjectID { get; set; } public string Description { get; set; } public System.DateTime StartDate { get; set; } public Nullable<System.DateTime> EndDate { get; set; } public System.DateTime ProjectedEndDate { get; set; } public int ProjectTypeID { get; set; } public virtual ProjectType ProjectType { get; set; } } public partial class ProjectType { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public ProjectType() { this.Projects = new HashSet<Project>(); } public int ProjectTypeID { get; set; } public string Description { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Project> Projects { get; set; } }
this.Projects = new HashSet<Project>();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)