Only parameterless constructors and initializers are supported in LINQ to Entities
salut a vous
je souhaite afficher sous forme de liste un ensemble d'informations predefinis dans mon modele mais lorque j'essaye de lancer l'affichage une exception de type NotSupportedException est levee en m'indiquant
Citation:
Only parameterless constructors and initializers are supported in LINQ to Entities
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| // modele
public class EtudiantModel
{
[Required]
[DisplayName("First name")]
public string FirstName { get; set; }
[Required]
[DisplayName("Last name")
public string LastName { get; set; }
[Required]
[DisplayName("Sexe")]
public string Sexe { get; set; }
[Required]
[DisplayName("Numero")]
public int? Numero { get; set; }
[Required]
[DisplayName("Contact")]
public string Contact { get; set; }
[Required]
[DisplayName("Matricule")]
public string Matricule { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[DisplayName("Email address")]
public string Email { get; set; }
[Required]
[DisplayName("EtudiantId")]
public int EtudiantId { get; set; }
[Required]
[DisplayName("Cycle")]
public string Cycle { get; set; }
[Required]
[DisplayName("options")]
public string options { get; set; }
[Required]
[DisplayName("Groupe")]
public string groupe { get; set; }
[Required]
[DisplayName("Niveau")]
public string Niveau { get; set; }
public EtudiantModel()
{ }
public EtudiantModel(string firstname, string lastname,string sexe,int?numero,string contact,string matricule,string email,string cycle,string option,string group,string niveau)
{
// TODO: Complete member initialization
FirstName = firstname;
LastName = lastname;
Sexe = sexe;
Numero = numero;
Contact = contact;
Matricule = matricule;
Email = email;
Cycle = cycle;
options = option;
groupe = group;
Niveau = niveau;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| //mon controller
public ActionResult ListeEtudiant()
{
// ViewData.Model = _db.Etudiants.ToList();
// return View();
var EtudiantListe = from et in _db.Etudiants
join etm in _db.EtudiantMatieres
on et.EtudiantId equals etm.EtudiantId
select new EtudiantModel(et.FirstName,et.LastName,et.Sexe,et.Numero,et.contact,et.Matricule,et.Email,etm.Cycles,etm.options,etm.groupe,etm.Niveau);
ViewData.Model = EtudiantListe;
return View();
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| //ma vue
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcApplication3.Models.EtudiantModel>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ListeEtudiant
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Liste des Etudiants</h2>
<table>
<tr>
<th></th>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
Sexe
</th>
<th>
Numero
</th>
<th>
Contact
</th>
<th>
Matricule
</th>
<th>
Email
</th>
<th>
Cycle
</th>
<th>
options
</th>
<th>
groupe
</th>
<th>
Niveau
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "EditEtudiant", new { id = item.EtudiantId})%> |
<%: Html.ActionLink("Delete", "DeleteEtudiant", new { id = item.EtudiantId })%>
</td>
<td>
<%: item.FirstName %>
</td>
<td>
<%: item.LastName %>
</td>
<td>
<%: item.Sexe %>
</td>
<td>
<%: item.Numero %>
</td>
<td>
<%: item.Contact %>
</td>
<td>
<%: item.Matricule %>
</td>
<td>
<%: item.Email %>
</td>
<td>
<%: item.Cycle %>
</td>
<td>
<%: item.options %>
</td>
<td>
<%: item.groupe %>
</td>
<td>
<%: item.Niveau %>
</td>
</tr>
<% } %>
</table>
<p>
<%: Html.ActionLink("Create New Etudiant", "AddEtudiant") %>
</p>
</asp:Content> |
pour ma part je ne conprend pas vraiment l'exception car je pense avoir depuis mon modele definis mon constructeur et meme l' initialisation de ces parametres.
ainsi toute aide, assistance ou conseil serait la bienvenue.
a++
Only parameterless constructors and initializers are supported in LINQ to Entities
salut a vous et merci pour l'assistance si je ne me trompe mon constructeur possède déjà un constructeur sans paramètres ceci à la ligne 56 de mon modèle.
a++ :P