self reference

Thread is closed for posting
2 posts, 0 answers
  1. Iftekhar Ivaan
    Iftekhar Ivaan avatar
    17 posts
    Member since:
    Apr 2006

    Posted 30 Mar 2009 Link to this post

    Hi,

    I am trying to do a self-referenced class where the class is referencing itself. Following is what I have done.
    parent is the self reference to do the parent child. It works but I am having problem when I am trying to find all the child for a class.

    string query = "SELECT * FROM RequirementExtent d where d.parent = " + br.Dbid ;
    IQueryResult result = scope.GetOqlQuery(query).Execute();

    or

    var tmp = from b in scope.Extent<Requirement>() where b.Parent == lookingfor select b;

    both are not working.

    what is the best way to get all the child for a object.

    public partial class Requirement
    {
            public int requirementDbid = -1;
     public Requirement parent = null;
            public String name = null;
            public String description = null;
            public DateTime createdOn;
            public User createdBy = null;
            public DateTime? modifiedOn;
            public User modifiedBy = null;
    }

     

  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 31 Mar 2009 Link to this post

    Hello Iftekhar Ivaan,

    The most probable reason for the behavior you are experiencing is the definition of your class. OpenAccess currently does not work properly when the persistent class is defined with public fields. The approach that should be used is declaring a private field and a property wrapper for it. Than you can use the property in your queries by attaching the filed alias attribute that points to the field that the property represents.

    For example:       private string name;

                                   [FieldAlias("name")]
                                   public string Name
                                   {
                                          get{ return this.name;}
                                          set{ this.name = value;}
                                   }

    If you have any further issues achieving your goal please feel free to contact us later or even send us your sample project.

    Kind regards,
    Zoran
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top