I have two entities in this case : Membre
inherits from Utilisateur
.
I have a ListView so I want to show the Membre
that is currently showed. The line that is generating the error is
Membre lemembre = (lecontexte.Set<Membre>().Find(membrealecran.Pseudo));
All I want this line to do is do a .Find(membrealecran.Pseudo)
... But I can't use the .Find
on Set<Membre>
.
It generates an System.ArgumentException and Data.EntitySqlException. It says Int32 and String are incompatible for the operation...
I can do a .Find
on Utilisateur
, but not on Membre
. Why? How could I do a Find
on Membre
?
protected void lvInscription_ItemDataBound(object sender, ListViewItemEventArgs e)
{
using (modele_vivo_amoreContainer lecontexte = new modele_vivo_amoreContainer())
{
try
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Membre membrealecran = (Membre)e.Item.DataItem;
Membre lemembre = (lecontexte.Set<Membre>().Find(membrealecran.Pseudo));
}
}
catch (Exception ex)
{
lblMessage.Text += "ERREUR DE ITEMDATABOUND, " + ex.ToString();
}
}
.Find
are seaching for entity by primary key. You need to pass primary key as parameter. Use SingleOrDefault
for seaching by non primary key param:
...
Membre lemembre = lecontexte.Set<Membre>().SingleOrDefault(m => m.Pseudo == membrealecran.Pseudo);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.