0

Web API ve NHibernate ORM ile uygulama oluşturun. Arama yöntemlerini kullanırken sorun yaşıyorum. NHibernate Fluent mapping'da birçok ilişki vardır. Örneğin:Web API NHibernate yanıtıyla özel serileştirme

public class Case : GuidEntityBase 
{ 
    public virtual CaseType CaseType { get; set; } 
    public virtual string CaseNumber { get; set; } 
    public virtual DateTime CaseDate { get; set; } 
    public virtual IList<Document> Documents { get; set; } 

    public Case() 
    { 
     Documents = new List<Document>(); 
    } 
} 

public class Document : GuidEntityBase 
{ 
    public virtual DocumentType DocumentType { get; set; } 
    public virtual string DocumentNumber { get; set; } 
    public virtual DateTime DocumentDate { get; set; } 

    public virtual Case Case { get; set; } 
} 

Yani çağırdığınızda

[Route("api/document/GetItem/{id}")] 
    [HttpGet] 
    public Document GetItem(string Id) 
    { 
     var response = service.GetItem(Id); 

     //response.Value.Case = null; 

     return response.Value; 
    } 

Ben belge veri almak, ama aynı zamanda vaka veri almak SameTime HttpGet aşağıdaki. Bu işlemi nasıl filtreleyebilirim? yanıt yazdım.Value.Case = null;, ancak çözüm için iyi bir yol değil.

+1

Neden tembel yükleme özelliğini kapatmıyorsunuz? Ben NHibernate kullanıcısı değilim, ama eminim, bunu yapmak için bir seçenek var. http://stackoverflow.com/questions/3142845/eager-loading-using-fluent-nhibernate-nhibernate-automapping – Dennis

+0

Çalışmıyor. –

cevap

3

Varlıkları birbirine göndermek kötü bir fikirdir, yapmanız gereken şey, görüşünüze dayalı bir model oluşturmak, doldurmak ve göndermek.

public class DocumentDto 
    { 
     public Guid Id { get; set; } 
     public DocumentType DocumentType { get; set; } 
     public string DocumentNumber { get; set; } 
     public DateTime DocumentDate { get; set; } 
    } 

    [Route("api/document/GetItem/{id}")] 
    [HttpGet] 
    public DocumentDto GetItem(string Id) 
    { 
     var doc = service.GetItem(Id).Value; 
     return new DocumentDto(){ 
      Id = doc.Id, 
      //set other properties from doc 
     }; 
    }