This is a migrated thread and some comments may be shown as answers.

self reference

1 Answer 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Iftekhar Ivaan
Top achievements
Rank 1
Iftekhar Ivaan asked on 31 Mar 2009, 12:13 AM

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;
}

 

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 31 Mar 2009, 02:55 PM
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.
Tags
General Discussions
Asked by
Iftekhar Ivaan
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or