Query on type object property

4 posts, 0 answers
  1. Frédéric
    Frédéric avatar
    2 posts
    Member since:
    Sep 2008

    Posted 20 Jul 2009 Link to this post

    Hi,
    My english is not really good so, I'll give you a sample.

    I have my class like that

    [persistent]
    public class TableDonnee
    {
    ...
    private Donnee _donnee;
    public Donnee Donnee
    {
      get {return _donnee;}
      set {_donnee = value;}
    }
    ...
    }

    [persistent]
    public class Donnee
    {
    ...
    private object _sousDonnee;
    public SousDonnee SousDonnee
    {
      get {return _sousDonnee;}
      set {_sousDonnee = value;}
    }
    ...
    }

    I type my property with object type because of circular references.

    My problem is to query on this data.
    When I do this query, I have an "reference type exception" :

    SELECT * FROM TableDonneeExtent AS TD WHERE TD._donnee._sousDonnee = $1

    Can you help me please ?!
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 21 Jul 2009 Link to this post

    Hello Frédéric,

    The problem is that the field has type Object instead of its actual type. Please, set it to the real type, this is the better way of having a reference. You said that there is a problem with circular references and that is why you use "objects". Maybe we should dig into this problem instead of thinking up workarounds. Please, elaborate a bit more what is failing in this scenario.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Frédéric
    Frédéric avatar
    2 posts
    Member since:
    Sep 2008

    Posted 22 Jul 2009 Link to this post

    Hello,

    To answer your question, here is some explainations of my solution.
    My solution is composed by N projects, one of them is a common project, so it is referenced by all the others, like that :
    - project #1 references common project
    - project #2 references common project
    - project #2 references project #1 ...
    - project #N references same projects as project #2
    so common project cannot references project #1 or others...

    The problem is that common project has a class with a property with a type defined in project #1, this is why I define my property using object type to avoid referencing project #1 in common project.

    I tried to create a persistent interface in an other project that contains all the interfaces of the whole solution (referenced by common project, project #1, ... all projects) and replaced the type of my property using my new interface type. But this effect is the same because in the database we still have the same two fields ([PropertyName]_class and [PropertyName]_id).

    In my opinion, the best solution would be to move this class from common project to project #2 (which references project #1) because only project #2 needs this class but it would be very hard and time consuming because moving a persistent class from a namespace to another results in data corruption (moved class id changes), and because it is more regression prone.

    This is why  a workaround is a better solution for me.

    Thanks
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 23 Jul 2009 Link to this post

    Hi Frédéric,

    I am afraid there is no workaround for this situation. In order to store a persistent object Telerik OpenAccess ORM needs to know its actual type, so all fields can be mapped to columns. I think the best solution in your case is to unite the common and #1 projects into one. As they depend on each other and the rest of the projects use both of them, that would not change or break the architecture. Hope this helps.

    All the best,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top