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

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

3 Answers 43 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Doron
Top achievements
Rank 1
Doron asked on 09 Jun 2013, 09:19 AM
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?

3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 13 Jun 2013, 07:34 AM
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.
0
Doron
Top achievements
Rank 1
answered on 31 Jul 2013, 08:23 AM
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
0
Accepted
Boris Georgiev
Telerik team
answered on 01 Aug 2013, 01:17 PM
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.
Tags
Development (API, general questions)
Asked by
Doron
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Doron
Top achievements
Rank 1
Share this question
or