19 messaggi dal 27 luglio 2009
Ciao, io ho creato i miei menu e tutto funziona bene e poi ho creato la mia classe MAGAZINE e quado ho generato le pagine, tutto ok, ma quando avvio l'applicazione si blocca :


L'erroe esce qui MagazineController.cs :

namespace CollectionHair.Controllers
{
public class MagazineController : Controller
{
private MagazineDbContext db = new MagazineDbContext();

// GET: /Magazine/
public ActionResult Index()
{
var magazines = db.Magazines.Include(m => m.ParentMenuMag).Include(m => m.ParentSubMenuMag);
return View(magazines.ToList());
}

// GET: /Magazine/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Magazine magazine = db.Magazines.Find(id);
if (magazine == null)
{
return HttpNotFound();
}
return View(magazine);
}

Questo é l'errore

+ $exception{"Introducing FOREIGN KEY constraint 'FK_dbo.SubMenus_dbo.Menus_MenuId' on table 'SubMenus' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.\r\nCould not create constraint. See previous errors."}System.Exception {System.Data.SqlClient.SqlException}

+ this{CollectionHair.Controllers.MagazineController}CollectionHair.Controllers.MagazineController

magazinesnullSystem.Linq.IQueryable<CollectionHair.Models.Magazine>



Questa é la mia classe Magazine.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace CollectionHair.Models
{
public class MagazineDbContext : DbContext
{
public DbSet<Menu> MagazineMenus { get; set; }
public DbSet<SubMenu> MagazineSubMenus { get; set; }
public DbSet<Magazine> Magazines { get; set; }
public DbSet<MagazineLike> MagazineLikes { get; set; }

}

public class Magazine
{
public int MenuId { get; set; }
public int SubMenuId { get; set; }
public int Id { get; set; }
[Key]
public int MagazineId { get; set; }

[StringLength(2000)]
public string MagazineTitle { get; set; }
[StringLength(2000)]
public string MagazineTitleEN { get; set; }
[StringLength(2000)]
public string MagazineTitleIT { get; set; }
[StringLength(2000)]
public string MagazineTitleSP { get; set; }
[StringLength(4000)]
public string MagazineBody { get; set; }
[StringLength(4000)]
public string MagazineBodyEN { get; set; }
[StringLength(4000)]
public string MagazineBodyIT { get; set; }
[StringLength(4000)]
public string MagazineBodySP { get; set; }

public bool MagazineVisible { get; set; }
public int MagazineOrder { get; set; }
public DateTime MagazineDate { get; set; }


[Required(ErrorMessage = "Please browse your image")]
[Display(Name = "Upload Image")]
[NotMapped]
[ValidateFile]
public HttpPostedFileBase MagazinePhoto { get; set; }
public string MagazinePhotoBis { get; set; }

public virtual Menu ParentMenuMag { get; set; }
public virtual SubMenu ParentSubMenuMag { get; set; }

public virtual ICollection<MagazineLike> Likes { get; set; }
}

public class MagazineLike
{
public int MagazineId { get; set; }
public int Id { get; set; }
[Key]
public int MagazineLikeId { get; set; }
public DateTime MagazineLikeDate { get; set; }

public virtual Magazine LikeParentMagazine { get; set; }

}

//Customized data annotation validator for uploading file

public class ValidateFileAttribute : ValidationAttribute
{

public override bool IsValid(object value)
{

int maxContent = 1024 * 1024; //1 MB

string[] sAllowedExt = new string[] { ".jpg", ".gif", ".png" };

var file = value as HttpPostedFileBase;

if (file == null)

return false;

else if (!sAllowedExt.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
{

ErrorMessage = "Please upload Your Photo of type: " + string.Join(", ", sAllowedExt);

return false;

}

else if (file.ContentLength > maxContent)
{

ErrorMessage = "Your Photo is too large, maximum allowed size is : " + (maxContent / 1024).ToString() + "MB";

return false;

}

else

return true;

}

}
}

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.