2014-10-07 2 views
0

비교적 간단한 도메인 모델에 몇 가지 POCO가 있습니다. FKS의SQLite가있는 LinqToDB - 참조 속성이 null입니다.

[Table("Tag")] 
public partial class Tag 
{ 
    [PrimaryKey, NotNull ] public string Name  { get; set; } // varchar(128) 
    [Column,  Nullable] public string Description { get; set; } // text(2147483647) 
    [Column,  Nullable] public string ParentID { get; set; } // varchar(128) 

    #region Associations 

    /// <summary> 
    /// FK_Tag_0_0 
    /// </summary> 
    [Association(ThisKey="ParentID", OtherKey="Name", CanBeNull=true)] 
    public Tag Parent { get; set; } 

    /// <summary> 
    /// FK_TagObjects_0_0_BackReference 
    /// </summary> 
    [Association(ThisKey="Name", OtherKey="TagID", CanBeNull=true)] 
    public List<TagObject> ObjectLinks { get; set; } 

    /// <summary> 
    /// FK_TagSynonyms_0_0_BackReference 
    /// </summary> 
    [Association(ThisKey="Name", OtherKey="TagID", CanBeNull=true)] 
    public List<TagSynonym> SynonymLinks { get; set; } 

    /// <summary> 
    /// FK_Tag_0_0_BackReference 
    /// </summary> 
    [Association(ThisKey="Name", OtherKey="ParentID", CanBeNull=true)] 
    public List<Tag> Children { get; set; } 

    #endregion 
} 

이름은 이상한,하지만 난 추가 정보 같은 .TT의 파일에 대한 MemberName의 지정에 의해 제안 반박 : 한 가지 예는 다음과 같습니다. 관련 태그에 대한 ParentID이 올바른지, 단지 Parent또는Children에 그지도를하지 않는 것 -

문제는 내가 내 태그 개체 중 하나를 잡아 때 협회의 모든 속성이 null 있다는 것입니다 내가 기대하는 것 같은 속성.

내가 여기 뭔가 잘못 했습니까? 데이터베이스 자체를 두 번 확인했습니다. .tt는 다음과 같이 보입니다.

답변

0

이것은 내가이 문제를 극복 한 방법입니다. Access db를 사용하고 있다는 것을 알고 있어야합니다.

[Table(Name = "Customers")] 
public class Customer 
{ 
    [PrimaryKey, Identity] 
    public int CompanyID { get; set; } 

    [Column(Name="CompanyName"), NotNull] 
    public string Name { get; set; } 

    [Association(OtherKey = "CompanyID", ThisKey = "CompanyID", CanBeNull = true)] 
    public Account Accounts { get; set; } 
} 

협회의 반환 형식이 IEnumrable, 아래의 사용이 된 IQueryable '<'는 IEnumerable '<'계정을 반환했다 >> 때.

사용법 : 답변

using (var db = new DbMain()) 
{ 
    var q = from c in db.Customers 
      select c.Accounts; 

    System.Diagnostics.Debug.Print(q.ToList()[0].AccountID); 
} 
+0

감사합니다! 그러나 나는 그것이 내 자신의 설정과 어떻게 다른지 잘 모르겠습니다. 두 경우 모두 LinqToDB를 삭제하기로 결정했으나 정보가 다른 사람에게 유용 할 수 있습니다. :) – robhol

관련 문제