Breeze客户端返回未定义的导航属性ID

时间:2015-05-31 07:29:32

标签: angularjs asp.net-web-api breeze asp.net-identity-2

我不知道为什么breeze.js没有显示我的数据库表中的所有数据,来自ASP Identity中applicationUsers的navaigation属性的字段未定义返回但是当我查询服务器上的breeze控制器资源端点时,一切正常{ {3}}

我不知道这与ASP身份有什么关系,或者我的代码有些问题。以下是需求信息。

/// User rehistration model for Patients and Doctors
public class ApplicationUser : IdentityUser
{

    [Required]
    [MaxLength(100)]
    public string FirstName { get; set; }

    [Required]
    [MaxLength(100)]
    public string LastName { get; set; }

    public virtual ICollection<Allergy> PatientAllergy { get; set; }
}


public class Allergy
{
    public int Id { get; set; }
    public string PatientId { get; set; }
    public string DoctorId { get; set; }
    public int LookupAllergyId { get; set; }
    public string Type { get; set; }
    public string Note { get; set; }

    public virtual LookupAllergy LookupAllergy { get; set; }//Navigation prop 1

    /// <summary>
    /// This section is from ASP.Net Identity
    /// </summary>
    [ForeignKey("PatientId")]
    public virtual ApplicationUser Patient { get; set; } //Navigation prop 2
    [ForeignKey("DoctorId")]
    public virtual ApplicationUser Doctor { get; set; }//Navigation prop 3

}

/// This is my configuration model
public class AllergyConfiguration : EntityTypeConfiguration<Allergy>
{
    public AllergyConfiguration()
    {
        HasRequired(s => s.Patient)
           .WithMany(p => p.PatientAllergy)
           .HasForeignKey(s => s.PatientId)
           .WillCascadeOnDelete(false);
    }
}

/// This is my angular Query using John Papa Code pattern johnpapa.net 
function getPatientAllAllergy() {
        var self = this;
        var allergy;
        var orderBy = 'type';

        return EntityQuery.from('Allergies')
            .select('id, lookupAllergyId, patientId, doctorId, type, note')
            .toType(entityName)
            .using(self.manager).execute()
            .then(querySucceeded, self._queryFailed);

        function querySucceeded(data) {
            allergy = data.results;
            self.log('Retrieved [Rev Allergy] from remote data source', diagnosis.length, true); 
            ///if i inspect the information from the log i found that patientId and doctorId are undefined while lookupAllergyId is return.
            return allergy;
        }
    }

查询返回所有其他实体数据但是PatientId和doctorId未定义,而患者和医生是'proto._setCtor.instanceProto'

Query from the server return this
PatientId: "a0bb54a2-c347-424c-bbf3-7c05e0286b43", 
DoctorId: "a0bb54a2-c347-424c-bbf3-7c05e0286b43",  
LookupAllergyId: 1 // return ok

Query from the client return this
id: (...)
doctor: proto._setCtor.instanceProto
doctorId: undefined // return undefined
lookupAllergy: (...)
lookupAllergyId: 1
modifiedBy: (...)
modifiedById: (...)
modifiedOn: (...)
note: (...)
patient: proto._setCtor.instanceProto
patientId: undefined // return undefined
type: (...)

请,我需要有关如何解决此问题的帮助,因为我的导航查询返回null,例如{{vm.allergy.patient.email}}是不可能的。

感谢。

0 个答案:

没有答案