How do I create a stored procedure with Entity Framework?
I read an old MSDN Forums post a开发者_Go百科bout Entity Framework where Julie Lerman stated:
wrt Stored Procedures. This is even better than what you are referring to. Not only can you map to sprocs (both in EF and in LINQ to SQL) or override the update/insert/delete methods, but in EF, there is coming a capability to CREATE stored procedures right in the mapping layer. Not create them and add them into the db, but just have them live in the EDM. So the sproc doesn't have to exist in the db.
This is not in the March bits, but I saw a demo of it last week and we will have it in the next CTP.
I want to see a demo of how this works, but it is excruciatingly hard to jump into such a huge framework and all of its documentation, and discover how to look at a single feature. From best as I can tell, Entity Framework is not dynamic enough to support the scenarios I want, at least not yet, but there are features discussed for future versions of EF that fit my needs. For now I am using a hand-rolled query generator, since the ORM features of EF do not fit my needs and I really just want an awesome query generator and the ability to create stored procedures and serialize Parameterized Queries.
Bottom line: So how does Entity Framework create stored procedures "live" without them existing a priori in the database? Is it customizable? How does it handle changes to the conceptual layer? And why would the mapping layer own this logic? Or is Julie just referring to something gross like T4 Templates (YUCK!!!)?
Julie's post seems a little vague. If it's not in the DB, it's not a "stored proc" as most people know it. I don't think she meant generate a proc; I don't think you can do that today, and I know you couldn't do it in 2007. Nor was T4 in use in 2007.
She may have been talking about EdmFunction, but it's hard to tell. She's pretty active on Twitter, so you could just ask her what she meant.
精彩评论