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

Domain Model - Stored Procedure - Result Mapping

7 Answers 219 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kurt
Top achievements
Rank 1
Kurt asked on 16 Jul 2010, 03:59 PM

I think what I want to do can only be accomplished manually, but thought I would ask anyway as it feels like this should be possible using the designer. 

When reverse engineering a database model, I had a number of stored procedures that return defined entities. The Open Access Domain Model reverse mapped this fine but  it created very generic function imports. For example

spProductsGet(@CategioryId INT)  -- turns into -> object[] spProductsGet(int CategoryId)

What would be helpful is the ability to map the rerun type, and be able to define the method name using the designer. This way I could have it do something like:

spProductsGet(@CategioryId INT)  -- be mapped to -> IList<Products> GetProducts(int CategoryId)

And still preserve the ability to make changes and update the model from the db.

An workaround alternative might be to change the code generator to use generics for the stored procedures.Ex:
public IList<T> spProductsGet<T>(int? categoryId) where T : class, new()
        {
            SqlParameter parameterCategoryId = new SqlParameter("CategoryId", OpenAccessType.Int32);
 
            List<SqlParameter> sqlParameters = new List<SqlParameter>()
            {
                parameterCategoryId
            };
 
            IList<T> queryResult = this.ExecuteStoredProcedure<T>("'spProductsGet' ?", sqlParameters, categoryId);
            return queryResult;
        }


7 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 19 Jul 2010, 06:11 PM
Hello Kurt,

We are currently reviewing our goal list for the Q3 release and this particular feature will be part of our discussion. We are considering implementing a way for the user to specify if a certain procedure returns a persistent type. 

For the time being however I suggest creating a partial class of the Context and writing similar methods as the one you have provided.

I hope this helps.

All the best,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daniel Plomp
Top achievements
Rank 2
answered on 29 Nov 2010, 03:59 PM
Hi,

I've curious if there is a way to set the EntityType for a stored procedure when using the domain model.
I'm using the latest version of OA.

Greetings,
Daniel
0
Serge
Telerik team
answered on 30 Nov 2010, 06:58 PM
Hi Daniel,

 At the moment this is not possible however we have planned it and it will be implemented for the next Service Pack or Q1 at the latest. The runtime is fully capable of returning typed result sets though, you can do a workaround at the moment in order to achieve your goal. You should manually write the code executing the stored procedures in methods in a partial class of the context that is generated by the domain model. 

As you can see by the generated calls to the stored procedures in the context that the ExecuteStoredProcedure API can take a type, and returning a typed result set is doable by just calling the method and providing the desired type as the generic parameter. 

I hope this is helpful.

Kind regards,
Serge
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
0
Daniel Plomp
Top achievements
Rank 2
answered on 30 Nov 2010, 07:02 PM
Hi Serge,

Thanks for the information.
I indeed managed to do it through the ExecuteStoredProcedure<> method, so it works.

Would be nice if this is supported by the designer.

Regards,
Daniel
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 06 Dec 2010, 04:33 AM
You wouldn't be able to share the code for that would you?

This compiles and runs, but I don't get results back

Is this close?

** EDIT**
Yeah, this works fine lol, I was just passing in the params in the wrong order :)

public List<Dictionary> GetRelatedDictionaryItems(string itemid, string itemType){
 
            List<Telerik.OpenAccess.SqlParameter> parameters = new List<Telerik.OpenAccess.SqlParameter>();
            parameters.Add(new Telerik.OpenAccess.SqlParameter("ItemID", Telerik.OpenAccess.OpenAccessType.Varchar));
            parameters.Add(new Telerik.OpenAccess.SqlParameter("ItemType", Telerik.OpenAccess.OpenAccessType.Varchar));
             
            List<Dictionary> items = new List<Dictionary>(this.ExecuteStoredProcedure<Dictionary>("GetRelatedDictionaryItems", parameters, new object[] {itemid, itemType}));
 
            return items;
        }
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 06 Dec 2010, 05:25 AM
Sorry to hijack this once more ;)

Is this only able to return types mapped to openaccess?

Server Error in '/' Application.

Only persistent types, object or object[] is allowed

0
Alexander
Telerik team
answered on 07 Dec 2010, 04:15 PM
Hello Steve,

Yes, at the moment only persistent classes can be used as return type of stored procedures. A possible workaround is to have a view in the database that encapsulates the columns returned from the stored procedure. Then you can add this view to your domain model and map the persistent class to the stored procedure result.

Best wishes,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Getting Started
Asked by
Kurt
Top achievements
Rank 1
Answers by
Serge
Telerik team
Daniel Plomp
Top achievements
Rank 2
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Alexander
Telerik team
Share this question
or