Print Page | Close Window

EDMX ComplexType and Stored procedure support

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1037
Printed Date: 28-Apr-2026 at 3:21am


Topic: EDMX ComplexType and Stored procedure support
Posted By: sebma
Subject: EDMX ComplexType and Stored procedure support
Date Posted: 26-Dec-2008 at 11:09pm
Hi,
 
This is a general question not specifically pertaining to DevForce EF, but more to MS ADO.NET EF.
 
WRT MSDN forum:  http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/5898271b-538c-467b-98a3-a4c574123a41/ - http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/5898271b-538c-467b-98a3-a4c574123a41/
 
I have a stored procedure that joins several tables and returns a result set, hypothetical example:
 
ALTER PROCEDURE [dbo].[GetBlaBlaBlaHistory]
    @EmployeeId uniqueidentifier
AS 
    
    SET NOCOUNT ON;
    SELECT ae.InternalId, e.FirstName, e.LastName, tv.Title, tv.Version, a.StartDateTime, a.EndDateTime, bct.Name 'AppointmentStatus'
    FROM RelatedEmployee ae
        INNER JOIN TableE e ON ae.EmployeeId = e.InternalId
        INNER JOIN TableA a ON ae.AppointmentId = a.InternalId 
        INNER JOIN TableBCT bct ON ae.AppointmentStatus = bct.InternalId
        INNER JOIN TableATV atv ON atv.AppointmentId = a.InternalId
        INNER JOIN TableTV tv ON tv.InternalId = atv.TrainingVersionId
    WHERE ae.EmployeeId = @EmployeeId
        AND ae.Status = 0
        AND e.Status = 0
        AND a.Status = 0
        AND bct.Name != 'Scheduled'
    ORDER BY a.EndDateTime DESC; 
 
Using just the steps from DevForce EF Developers Guide on Store Procedure Queries, page 215, I am not able to build and run, unless the resulting entityset maps to "something with metadata", as in either table or view.
 
At this point, I cannot use stored procedure queries, I can only use sql view.
 
Has anyone has similar stored proc issues like this?
 
Thanks!
Sebastian
 



Replies:
Posted By: kimj
Date Posted: 28-Dec-2008 at 5:00pm

Sebastian, I'm not sure I understand - are you trying to use a ComplexType as the sproc return type here?  Per the thread you referenced, that's not supported in EF v1 or DevForce EF.

If you don't want to map to a ComplexType, what you need to do is create a "fake" EntityType in both your conceptual and storage models shaped like the returned data.  You can't do this (at least not the SSDL EntityTpe) using the designer - you'll need to work in the EDMX directly.  We can put together a sample showing what this looks like if you think that would help.
 


Posted By: sebma
Date Posted: 28-Dec-2008 at 8:09pm
Yes, it will be great if you can supply a sample, just a simple one without the insert/update/delete stored procs, only a stored proc joining together a few tables and return the result set. Oh, btw, will the "fake" EntityTypes defined manually in edmx going to be removed everytime we update model from database (hope not) ?
 
Cheers
Sebastian


Posted By: kimj
Date Posted: 29-Dec-2008 at 12:58pm
Here's a sample EDMX for a stored proc called "SalesbyYear".  This sproc is not in the NorthwindIB sample database unfortunately, so the SQL to generate it is also included in the zip.
 
Irritating, but true - the fake EntityType will be removed from the storage model, along with the mapping, any time you update the model from the database.   This is a limitation of the EF v1 designer.
 
http://www.ideablade.com/forum/uploads/11/SampleProc.zip - uploads/11/SampleProc.zip


Posted By: sebma
Date Posted: 30-Dec-2008 at 2:20am

Thank-you Kim!




Print Page | Close Window