C# WCF Rest代码首先可以';t返回外键表中的列表
首先,我不了解WCF Rest和代码。如果我有一个单独的病人。我可以有一个没有问题的所有患者的列表,但是如果我有一个用户表,并且患者表上有一个外键。我没有我的病人名单。 我希望我足够清楚。你可以在下面找到我的代码 我的服务 伊瑟薇 使用者C# WCF Rest代码首先可以';t返回外键表中的列表,c#,entity-framework,code-first,C#,Entity Framework,Code First,首先,我不了解WCF Rest和代码。如果我有一个单独的病人。我可以有一个没有问题的所有患者的列表,但是如果我有一个用户表,并且患者表上有一个外键。我没有我的病人名单。 我希望我足够清楚。你可以在下面找到我的代码 我的服务 伊瑟薇 使用者 [表(“利用者”)] 公共部分类利用者 { [System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInCons
[表(“利用者”)]
公共部分类利用者
{
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInConstructors”)]
公共用途
{
Patient=新HashSet();
}
[关键]
公共Guid id_usilizateur{get;set;}
[第15段]
公共字符串uti_titre{get;set;}
[长度(100)]
公共字符串uti_nom{get;set;}
[长度(100)]
公共字符串uti_prenom{get;set;}
[长度(50)]
公共字符串uti_登录{get;set;}
[长度(200)]
公共字符串uti_密码{get;set;}
公共Guid?uti_Id_cabinet{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection患者{get;set;}
}
有人能给我解释一下问题是什么吗?
提前谢谢
致以最诚挚的问候我想您无法获取国外表格“患者”的数据 尝试在您的类中设置引用,然后尝试调用此“患者”表
你有错误吗?到底是什么问题?我正在用邮递员测试我的rest服务。邮递员寄给我的邮件没有得到任何回复。我的rest服务好像因为另一张桌子而无法应答。如果没有链接bwtween表,它就工作了。使用此参考资料,我认为它会对您有所帮助。
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;
}
}
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; }
}
[ForeignKey("Your Foreign Key")]
public virtual Patient patient { get; set; }