c# - WCF Rest Code First Can't return a list in a feign key table -
i don't understand wcf rest , code first. if have table patient alone. can have list of patient without problem if have user table , patient table have foreign key on it. can't have list of patient. hope i'm clear enough. find code below service iservice
namespace handyifeservice { [servicecontract] public interface ihandyservce { [operationcontract] [webinvoke(method = "get", requestformat = webmessageformat.json, responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare, uritemplate = "test")] list<patient> getpatientlist(); } }
service
public class handyservice : ihandyservce { public list<patient> getpatientlist() { list<patient> listpatients = (from pat in mobile.patient select pat).tolist(); return listpatients; } }
code first datamodel
public partial class model1 : dbcontext { public model1() : base("name=model1") { } public virtual dbset<patient> patient { get; set; } public virtual dbset<utilisateur> utilisateur { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<patient>() .property(e => e.pat_nom) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_prenom) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_adresse) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_ville) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_pays) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_natel) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_teleèhone) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_nommere) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_prenommere) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_nompere) .isunicode(false); modelbuilder.entity<patient>() .property(e => e.pat_prenompere) .isunicode(false); modelbuilder.entity<utilisateur>() .property(e => e.uti_titre) .isunicode(false); modelbuilder.entity<utilisateur>() .property(e => e.uti_nom) .isunicode(false); modelbuilder.entity<utilisateur>() .property(e => e.uti_prenom) .isunicode(false); modelbuilder.entity<utilisateur>() .property(e => e.uti_login) .isunicode(false); modelbuilder.entity<utilisateur>() .property(e => e.uti_password) .isunicode(false); modelbuilder.entity<utilisateur>() .hasmany(e => e.patient) .withoptional(e => e.utilisateur) .hasforeignkey(e => e.pat_id_utilisateur); } }
patient
[table("patient")] public partial class patient { [key] public guid id_patient { get; set; } [stringlength(255)] public string pat_nom { get; set; } [stringlength(255)] public string pat_prenom { get; set; } public datetime? pat_datenaissance { get; set; } [stringlength(255)] public string pat_adresse { get; set; } public int? pat_npa { get; set; } [stringlength(255)] public string pat_ville { get; set; } [stringlength(255)] public string pat_pays { get; set; } [stringlength(255)] public string pat_natel { get; set; } [stringlength(255)] public string pat_teleèhone { get; set; } [stringlength(255)] public string pat_nommere { get; set; } [stringlength(255)] public string pat_prenommere { get; set; } [stringlength(255)] public string pat_nompere { get; set; } [stringlength(255)] public string pat_prenompere { get; set; } public datetime pat_creation { get; set; } public datetime pat_update { get; set; } public guid? pat_id_cabinet { get; set; } public guid? pat_id_utilisateur { get; set; } public virtual utilisateur utilisateur { get; set; } }
user
[table("utilisateur")] public partial class utilisateur { [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2214:donotcalloverridablemethodsinconstructors")] public utilisateur() { patient = new hashset<patient>(); } [key] public guid id_utilisateur { get; set; } [stringlength(15)] public string uti_titre { get; set; } [stringlength(100)] public string uti_nom { get; set; } [stringlength(100)] public string uti_prenom { get; set; } [stringlength(50)] public string uti_login { get; set; } [stringlength(200)] public string uti_password { get; set; } public guid? uti_id_cabinet { get; set; } [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2227:collectionpropertiesshouldbereadonly")] public virtual icollection<patient> patient { get; set; } }
can explain me problem is? in advance best regards
i think can't data of foreign table "patient"
try set reference in class try call "patient" table.
[foreignkey("your foreign key")] public virtual patient patient { get; set; }
Comments
Post a Comment