Is there a way to specify that a domain method returns at most 1 row/object

4 posts, 1 answers
  1. Doron
    Doron avatar
    8 posts
    Member since:
    Apr 2013

    Posted 09 Jun 2013 Link to this post

    In a lot of cases i have SP that return a single row/object to my C# code

    i can define then using openaccess as domain methods, and call them, but i always need to wrap my calls with a call to .first() or .firstOrDefault() in order to work with them properly.

    Is there a way to specify that to OA so that extra call will be hidden inside?
  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 13 Jun 2013 Link to this post

    Hi Doron,

    Telerik OpenAccess ORM does not analyze the code behind the stored procedure and that is why the return value from the stored procedure is IEnumerable

    In your case I would recommend you to extend the Domain Model in partial class and create a wrapper of the generated method, which will return First() or FirstOrDefault().

    For your convenience I have prepared a code sample:
    public partial class EntitiesModel
    {
        public Car GetFirstCarWrapper()
        {
            return this.GetFirstCar().FirstOrDefault();
        }
    }

    Assuming that there is a stored procedure GetFirstCar which is mapped to a method :
    public IEnumerable<OpenAccessModel.Car> GetFirstCar()
    {
        IEnumerable<OpenAccessModel.Car> queryResult = this.ExecuteQuery<OpenAccessModel.Car>("[GetFirstCar]", CommandType.StoredProcedure);
     
        return queryResult;
    }

    I hope that helps.
     

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
  3. DevCraft banner
  4. Doron
    Doron avatar
    8 posts
    Member since:
    Apr 2013

    Posted 31 Jul 2013 Link to this post

    any chance this is something you will add?
    in the same way i choose in the OA UI what type domain method returns - i could specify whether i am returning an ienumerable, first or FirstOrDefault

    you do have this distinction in your UI for scalar - why not for more complex object
  5. Answer
    Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 01 Aug 2013 Link to this post

    Hi Doron,

    I am sorry for the insufficient answer in my previous post.

    We are considering to implement this feature and it is in our backlog, but I am not able to give you an estimate when to expect it.

    At the moment as a workaround for your convenience I have attached a set of modified code generation templates, so for every stored procedure which returns IEnumerable<Persistent Type> or IEnumerable<Complex Type>, one more domain method will be generated which returns the FirstOrDefault() object from the collection. In the DomainMethodsGenerator.ttinclude file the new code is surrounded with comments: 
    //Code Geration modification - Begin
    ...
    //Code Geration modification - End

    The new method will have the same name as the default domain method but with FirstOrDefault as a suffix.

    You should have in mind, that this modification will generate a new method for every stored procedure which returns Persistent Type or Complex Type.

    For further information how to customize code generation templates refer to this article.

    I hope that helps.
     

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top