我不明白关于WCF休息和代码优先。如果我有一张桌子病人独自一人。我可以没有问题地列出所有患者的列表,但是如果我有用户表并且患者表上有一个外键。我无法获得患者列表。 我希望我很清楚。你会发现下面 我的服务我的代码 IserviceWCF其余代码先不能返回一个假名密钥表中的列表
namespace HandyifeService
{
[ServiceContract]
public interface IHandyServce
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Test")]
List<Patient> GetPatientList();
}
}
服务
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);
}
}
患者
[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; }
}
用户
[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; }
}
有人可以向我解释什么问题是? 预先感谢 问候
你有什么错误吗?究竟是什么问题? –
我使用邮差来测试我的休息服务。邮差发送我无法得到任何回应。这就像我的休息服务无法回答,因为其他表。没有表格之间的链接,它正在工作。 – Ludovic