casting IQueryResult to domain object

Thread is closed for posting
2 posts, 1 answers
  1. Bill
    Bill avatar
    21 posts
    Member since:
    May 2008

    Posted 19 Nov 2009 Link to this post


    I am calling a stored procedure that returns an address object. The orm returns it as an IQueryResult object. In my domain, I have an address class with the exact same properties as what the IQueryResult  object has. Is there a way to direct cast the IQueryResult  to the address type in the domain? How can I cast the orm IQueryResult  object to the address class in the domain?

  2. Answer
    PetarP avatar
    754 posts

    Posted 20 Nov 2009 Link to this post

    Hello Bill,

    When returning a result from a stored procedure you have two options:
    1. The stored procedure will either return an entire persistent class (in your case an entire address object)
    2. A projection based on single or multiple tables will be returned. In that case there is no way to map the result to a specific class so it is transferred to an object array instead.

    If you are returning an entire object then you can set the return type of the stored procedure to be a specific persistent class. This can be achieved through the reverse mapping wizard:
    1. Run the reverse mapping wizard.
    2. Go to the Advanced View tab.
    3. Select the stored procedure you wish to generate
    4. Select from the Result combo box the persistent class that will be returned.
    5. Set the generate method property to true.
    6. Click Generate & Save config.
    Using this approach you can map the result of a stored procedure to a specific persistent class.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top