If I understand well your problem. The three properties are your keys but not your primary keys as I saw in your code you just added comments to precise that the CAT_ID
and C_GARANT
are your foreign keys.
Regarding the first try. Meaning only Taux_ID
is your Primary Key.
If you want the extension method Find
work you need to precise the attribute Key
above the property which is in your table is the primary key.
In your case you could have:
Edit
public partial class TAUX
{
public int TAUX_ID { get; set; }
[Required(ErrorMessage = "Taux est obligatoire")]
public decimal POURC_TAUX { get; set; }
public System.DateTime DATE_EFFET { get; set; }
public short CAT_ID { get; set; } // foreign key
public virtual CATEGORIE CATEGORIE { get; set; }
public int C_GARANT { get; set; } // foreign key
public virtual GARANTIE GARANTIE { get; set; }
}
Then in your Action, don't change:
public ActionResult Edit(int id=0, int cat_Id =0,short c_garant=0)
{
TAUX taux = db.TAUX.Where(p=>p.TAUX_Id==id &&p.CAT_ID==cat_Id && p.C_GARANT==c_garant).FirstOrDefault();
if (taux == null)
{
return HttpNotFound();
}
ViewBag.CAT_ID = new SelectList(db.CATEGORIE, "CAT_ID", "LIBELLE", taux.CAT_ID);
ViewBag.C_GARANT = new SelectList(db.GARANTIE, "C_GARANT", "LIB_ABREGE", taux.C_GARANT);
return PartialView("_Edit",taux);
}