Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

ADO.Net Entity Framework: Map Store Procedure

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
ulf-jzl
Asked:
ulf-jzl
  • 5
  • 4
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
It's not possible with the current version of EF to map a single stored procedure to multiple entities.
0
 
ulf-jzlAuthor Commented:
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
 
ulf-jzlAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Carl TawnSystems and Integration DeveloperCommented:
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
 
ulf-jzlAuthor Commented:
ok, do you have any tips how to solve it. leave EF4 for regular ADO.Net to solve this?
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
ulf-jzlAuthor Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
Yes, only you'll need to repeat the "cmd.Parameters.Add" line for each property you need to pass to the SP.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Except you will use "ExecuteNonQuery()" instead of "ExecuteReader()", if you don't return any data back.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now