Using Stored Procedure with Entity Framework where SP Parameters don't match entity
I have stored procedures that take a user's username (to log who makes changes to the database) in addition to other information (like name, ID, email, etc.). Within the stored procedure I look up the user's ID and store that in the table.
The issue I am experiencing is that the Entity Table does not match the in开发者_如何学运维put of the stored procedure, therefore there is no way to map (or include) the user's username.
Is there a standard way to include non-entity properties in a stored procedure mapping?
If I get your question correctly (not entirely sure I do), then:
- If you aren't already using your own DataContext derived class, do so.
- Add a method that calls ExecuteMethodCall in that class (it's protected, so you can only call it from a derived type, passing in "raw" types (the relevant strings, ints, datetimes, etc. rather than instances of entity classes).
- Add a method (presumably to your entity class, though it could live elsewhere) that does the necessary work for obtaining the username (whether it's a member of your class or input from elsewhere etc. isn't clear in your question) and calls the method on your DataContext-derived class.
Hope that's useful, and I'm not mis-reading.
I created an XSLT stylesheet to generate C# methods from mapped Function Imports in the edmx. This solution works with VS2008.
精彩评论