简体   繁体   中英

How do you create a complex type by hand on a POCO implementation of Entity Framework

I'm using entity framework, however have turned off the code generation and am using my own poco classes (as detailed here http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx ). This has been fine thus far, adding in entities to expose a bunch of tables to querying, however the time has come where I wish to expose a stored procedure. This is not so simple- how do I write a create a complex type myself and then wire that up to the entity model?

I import the functional reference on the edmx, I can set a return type to be complex, and even click generate, but this is unusable because I'm not using the automatic code generation. So I need to be able to create my own, which will then appear in that list for me to select, and then be able to create the corresponding entry in my entity context class. The only information online seems to be generating complex classes through the visual interface. I'm reluctant to edit the edmx file manually as it will only get wiped out if it gets re-generated.

I have so far tried;

  • Adding the function to my context class without putting it in the edmx; this obviously broke with an Invalid Operation Exception "The FunctionImport 'GetT4OpenCases' could not be found in the container 'EclipseEntities'."

  • Adding the function to the edmx, and setting the return type to none, then adding my function to the context with my hand coded complex type, where I see another invalid operatino exception "The stored procedure or function 'GetT4OpenCases' does not have a return type. ExecuteFunction only supports stored procedures and functions that have a return type. "

I'm at a loss!

Thanks.

Ok it turns out this is pretty simple-- In the edmx file

  • Update the data model to include the stored proc I want
  • Create a functional import
  • In the popup, select Create Complex Type
  • Create a new class which conforms to the same name/ has same properties as the proposed complex type
  • Add entry to your manual context class such as;

    public IEnumerable GetT4Brokers() { return base.ExecuteFunction("GetT4Brokers"); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM