Entity Framework - Can you map the result type of an imported stored procedure to a custom entity type?

By : Vyrotek
Source: Stackoverflow.com
Question!

I already have an entity model in a separate dll that contains various objects that I need to use. I don't really want to create or duplicate entities using the EF designer. Instead I would like to configure it so that when I call a stored procedure it will map certain columns to specific properties.

I know you can do something VERY close to this using a custom DataContext in LinqToSql. The problem is you can't assign columns to complex property types. For example: I might have a columns returned that contain the address for a user. I would like to store the address details for the user in an Address object that is a property of a User object. So, Column STREET should map to User.Address.Street.

Any ideas?

By : Vyrotek


Answers

There are a couple of options here.

  1. You can create a "Complex Type" and map that to the procedure result. However, you have to do that in your EDMX; it's not supported by the designer. Read this article for details. Note that Complex Types are not entity types per se, so this may or may not fit your needs. But you can find examples for stored procs which use "Address".

  2. You can change the visibility of your procedure to private, and then write a public interface for it in any manually-written partial class file which does the mapping that you want. Or just overload the procedure.



CodeLite is a free, powerful, cross platform and open source IDE for C/C++ programming. It can import MSVS workspace/projects and convert them to use a GNU-based makefile. IMO it's much better than Code::Blocks.

By : Rob Kam


http://www.caerwyn.com/acme/

/me using acme in plan9port/linux

HTH



This video can help you solving your question :)
By: admin