Solved

ADO.Net Entity Framework: Map Store Procedure

Posted on 2011-02-24
9
599 Views
Last Modified: 2012-05-11
Hi guys!

Need some help with mapping a store procedure to this model..

I tried using TPT inheritence but with no luck.

If this is not possible, any other solutions?

(The store procedure I have takes values for all for all three tables.)
tables.JPG
0
Comment
Question by:ulf-jzl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34967947
It's not possible with the current version of EF to map a single stored procedure to multiple entities.
0
 

Author Comment

by:ulf-jzl
ID: 34968154
If I use TPT and have one to one relationship it would work, the problem is the one to many relationship i have in the first two tables.

any tips how to change the architecture to solve this?
0
 

Author Comment

by:ulf-jzl
ID: 34971994
it sould be solved by using the Entity Framework Extensions, but I can't figure out how to do that.
Any tips on that?
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34972063
Not something i've used myself i'm afraid. From what i have read it supports pulling back multiple entities from a single procedure, but i haven't seen anything about going the other way.
0
 

Author Comment

by:ulf-jzl
ID: 34972249
ok, do you have any tips how to solve it. leave EF4 for regular ADO.Net to solve this?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34972318
You can do it easily enough with ADO.Net. You would need to manually create a parameter for each property of your enitites, but other than that its all straightforward stuff. Let su know if you need any help with it.
0
 

Author Comment

by:ulf-jzl
ID: 34972495
something like this then?

Or can I use somehting form the model to make this better?

public static void InsertDeviceTestResults(string deviceId)
        {
            // create and open a connection 
            using (SqlConnection conn = new SqlConnection("Server=(local);DataBase=FBI.Data;Integrated Security=SSPI"))
            {
                // Open connection
                conn.Open();

                // Setup command
                SqlCommand cmd = new SqlCommand("InsertDeviceTestResults", conn) { CommandType = CommandType.StoredProcedure };

                // Add parameter to the stored procedure
                cmd.Parameters.Add(
                    new SqlParameter("@DeviceId", deviceId));

                // Execute the sproc
                cmd.ExecuteReader();
            }
        }

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34973333
Yes, only you'll need to repeat the "cmd.Parameters.Add" line for each property you need to pass to the SP.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34973341
Except you will use "ExecuteNonQuery()" instead of "ExecuteReader()", if you don't return any data back.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question