<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx</link><description>Today the Entity Framework, and more specifically the Entity Data Model, have a limited notion of Functions. We are currently restricted to Function Imports that allow stored procedures to be invoked, and Canonical / Store Functions for database independent</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301174</link><pubDate>Fri, 09 Jan 2009 05:13:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301174</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;Sorry, but for consistency shouldn't the DefiningExpression part live in the SSDL rather than the CSDL?&lt;/p&gt;
&lt;p&gt;I.e. declare the function's signature in CSDL, declare the function itself in SSDL and map the two in MSL...&lt;/p&gt;
&lt;p&gt;I think that would be more consistent with how everything else is done today in EDMX.&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301189</link><pubDate>Fri, 09 Jan 2009 05:27:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301189</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;...or maybe I am misunderstanding what you're trying to achieve.&lt;/p&gt;
&lt;p&gt;To make the problem/solution at hand easier to understand - could you elaborate on what are the benefits of defining the ESQL part in the CSDL and/or what problem you're trying to solve?&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301346</link><pubDate>Fri, 09 Jan 2009 08:06:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301346</guid><dc:creator>AlexJ</dc:creator><description>&lt;p&gt;Kristofer,&lt;/p&gt;
&lt;p&gt;I'm not sure that there is anything inconsistent about having something live purely in the CSDL.&lt;/p&gt;
&lt;p&gt;Having said that declaring and defining (with native SQL) a function in the SSDL and mapping that through to a CSDL declaration is an interesting scenario. And is closely related to something we are considering for Table Value Functions. This is why today if you only have a declaration in the CSDL, it won't fail at metadata loadtime, it means in the future we can support that declaration mapping to something in the SSDL.&lt;/p&gt;
&lt;p&gt;Still there are a number of benefits of functions declared and defined purely in the CSDL:&lt;/p&gt;
&lt;p&gt;1) The functions don't rely on anything in the MSL or SSDL, i.e. they are fully portable.&lt;/p&gt;
&lt;p&gt;2) In eSQL you get to write functions in terms of the conceptual model, rather than in terms of the storage model. I.e. you don't need to worry about things like joins for either inheritance or associations, the existing mapping takes care of that.&lt;/p&gt;
&lt;p&gt;3) Since the entity framework can parse and understand eSQL (as opposed to native SQL) we can potentially optimize calls to retrieve only what is required when less than is returned is actually required by the calling code (eSQL or LINQ). &lt;/p&gt;
&lt;p&gt;There are probably other advantages but that is what is coming to mind right now.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301359</link><pubDate>Fri, 09 Jan 2009 08:25:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301359</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;Thanks, that makes it more clear. Esp. #2 is a very good reason for doing this.&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301368</link><pubDate>Fri, 09 Jan 2009 08:32:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301368</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;Will you also allow CSDL functions to map to managed code implementations?&lt;/p&gt;
&lt;p&gt;E.g.:&lt;/p&gt;
&lt;p&gt;&amp;lt;Function Name=&amp;quot;GetAge&amp;quot; ReturnType=&amp;quot;Edm.Int32&amp;quot;&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Parameter Name=&amp;quot;Person&amp;quot; Type=&amp;quot;Model.Person&amp;quot; /&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;ManagedMethod Name=&amp;quot;GetPersonAge&amp;quot; assembly=&amp;quot;PersonExtensions.AgeCalculator, Version=1.2.3295.12345, Culture=neutral, PublicKeyToken=123412341234ABCD&amp;quot; /&amp;gt; &lt;/p&gt;
&lt;p&gt;&amp;lt;/Function&amp;gt; &lt;/p&gt;
&lt;p&gt;That would provide a nice extensibility point allowing plugins that would also be used by 'other' consumers of the model (e.g. reporting tools etc).&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301372</link><pubDate>Fri, 09 Jan 2009 08:40:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301372</guid><dc:creator>AlexJ</dc:creator><description>&lt;p&gt;Kristofer,&lt;/p&gt;
&lt;p&gt;We have discussed the possibility of a language attribute on the &amp;lt;DefiningExpression&amp;gt; basically for the scenario you talk about. &lt;/p&gt;
&lt;p&gt;However that is definitely more of an V3/V4 kind of a thing, you shouldn't expect to have built-in support for this in .NET 4.0 (i.e. EF v2).&lt;/p&gt;
&lt;p&gt;Having said that however it will be possible to not include a DefiningExpression and instead have your own structural annotation (see the post on structural annotations on this blog) i.e. &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;lt;mynamespace:ManagedMethod Name=&amp;quot;GetPersonAge&amp;quot; assembly=&amp;quot;PersonExtensions.AgeCalculator, Version=1.2.3295.12345, Culture=neutral, PublicKeyToken=123412341234ABCD&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;And use that to support other consumers of the model.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301376</link><pubDate>Fri, 09 Jan 2009 08:45:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301376</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;...and... While we're in on the topic of providing extensibility that can be used by all consumers of the model... How about CSDL functions mapped to webservice (and WCF) calls, e.g.:&lt;/p&gt;
&lt;p&gt;&amp;lt;Function Name=&amp;quot;GetMarkToMarketValue&amp;quot; ReturnType=&amp;quot;Decimal&amp;quot;&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;lt;Parameter Name=&amp;quot;MarketTransaction&amp;quot; Type=&amp;quot;Model.MarketTransaction&amp;quot; /&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;lt;WebServiceMethod Name=&amp;quot;GetMarkToMarketValue&amp;quot; URL=&amp;quot;&lt;a rel="nofollow" target="_new" href="http://hedgehog.huagati.com/test/marktomarket.asmx&amp;quot;"&gt;http://hedgehog.huagati.com/test/marktomarket.asmx&amp;quot;&lt;/a&gt; /&amp;gt; &lt;/p&gt;
&lt;p&gt;&amp;lt;/Function&amp;gt; &lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301397</link><pubDate>Fri, 09 Jan 2009 09:07:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301397</guid><dc:creator>Alex James</dc:creator><description>&lt;p&gt;Ah, someone who thinks a little like me ;)&lt;/p&gt;
&lt;p&gt;Well one of the scenarios I see for &amp;lt;Function&amp;gt;s with no &amp;lt;DefiningExpression&amp;gt;, maybe with structural annotations, is the creation of WebService end points etc.&lt;/p&gt;
&lt;p&gt;Given that we are adopting customizable T4 templates for Code Generation (not to mention model first scenarios) in the Entity Framework, I think you can imagine the possibilities.&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301455</link><pubDate>Fri, 09 Jan 2009 09:51:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301455</guid><dc:creator>Kristofer</dc:creator><description>&lt;p&gt;Neat, will the default code generator in v2 be T4 based?&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301526</link><pubDate>Fri, 09 Jan 2009 10:58:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301526</guid><dc:creator>dsimmons@microsoft.com</dc:creator><description>&lt;p&gt;Yes, the default code generator in v2 will be T4 based, but in a sense that will just be an implementation detail. &amp;nbsp;The interesting part really is just that we will have fully supported templates as a starting point and some tooling integration to make it easy to turn off the default code generator and drop into your project the template so that you can begin customizing it (or even pick from multiple different flavors of templates as starting points).&lt;/p&gt;
&lt;p&gt;- Danny&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301948</link><pubDate>Fri, 09 Jan 2009 16:55:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301948</guid><dc:creator>juliel</dc:creator><description>&lt;p&gt;Are we witnessing a job interview here? ;-)&lt;/p&gt;
&lt;p&gt;I wonder if anyone has complained that you are putting business logic into the model with this?&lt;/p&gt;
&lt;p&gt;Will there be designer support for this? Not for the building the expression itslef but so that you don't have to go into the XML to implement it.&lt;/p&gt;
&lt;p&gt;julie&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9301958</link><pubDate>Fri, 09 Jan 2009 17:01:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9301958</guid><dc:creator>juliel</dc:creator><description>&lt;p&gt;BTW - I wasn't complaining about business logic, just curious about feedback from others. Alex, you know I'm a fan of definingExpression. &lt;/p&gt;
&lt;p&gt;julie&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9302804</link><pubDate>Sat, 10 Jan 2009 01:21:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9302804</guid><dc:creator>efdesign</dc:creator><description>&lt;p&gt;Julie,&lt;/p&gt;
&lt;p&gt;I'm sure some will complain. We all have different ideas about how things should be done. &lt;/p&gt;
&lt;p&gt;Personally I don't see the conceptual difference between a Model Defined Function and WebService end point. The only difference is that the Entity Framework automatically handles calls to the MDFs.&lt;/p&gt;
&lt;p&gt;And given that you can write Model Declared Functions too (i.e. no definition) you can separate out the implementation from the declaration too, if you think that is important. &lt;/p&gt;
&lt;p&gt;If you do that of course, then you need to handle calls to the function yourself.&lt;/p&gt;
&lt;p&gt;Am I making any sense?&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9304689</link><pubDate>Sun, 11 Jan 2009 00:09:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9304689</guid><dc:creator>shawn</dc:creator><description>&lt;p&gt;Would it be possible to do this for non-static functions as well, so that you can write the queries in a more object-oriented way? &amp;nbsp;So instead of:&lt;/p&gt;
&lt;p&gt;var peopleOver21 =&lt;/p&gt;
&lt;p&gt;from p in ctx.People&lt;/p&gt;
&lt;p&gt;where GetAge(p) &amp;gt; 21&lt;/p&gt;
&lt;p&gt;select p;&lt;/p&gt;
&lt;p&gt;Could you map it such that you could query like this:&lt;/p&gt;
&lt;p&gt;var peopleOver21 =&lt;/p&gt;
&lt;p&gt;from p in ctx.People&lt;/p&gt;
&lt;p&gt;where p.Age &amp;gt; 21&lt;/p&gt;
&lt;p&gt;select p;&lt;/p&gt;
&lt;p&gt;That way you are calling p.Age instead of GetAge(p)? &amp;nbsp;It seems like that would be a cleaner, more OO way to consume the data in many cases.&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9306730</link><pubDate>Mon, 12 Jan 2009 05:29:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9306730</guid><dc:creator>efdesign</dc:creator><description>&lt;p&gt;Shawn,&lt;/p&gt;
&lt;p&gt;Well it is not something we have done yet. But it is something we are considering. All we need to do is allow the [EdmFunction] attribute on properties and treat the declaring class as the first parameter in the MDF implicitly&lt;/p&gt;
&lt;p&gt;Sort of like the reverse of Extension Methods I suppose.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;
</description></item><item><title>Update on Computed Properties</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9312719</link><pubDate>Tue, 13 Jan 2009 07:27:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9312719</guid><dc:creator>Entity Framework Design</dc:creator><description>&lt;p&gt;A while back I wrote a post that introduced the concept of Computed Properties . Since that time we’ve&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9457161</link><pubDate>Tue, 03 Mar 2009 20:59:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9457161</guid><dc:creator>Bruno Santos</dc:creator><description>&lt;p&gt;Hi. That's a great post! Its exacly what I wanted.&lt;/p&gt;
&lt;p&gt;The problem is, it seems the atribute doesn't exist in the VB.NET is that possible?&lt;/p&gt;
&lt;p&gt;I can only find 2 sites exposing this subject, yours and this:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx"&gt;http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Entity Framework Design : Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9614856</link><pubDate>Thu, 14 May 2009 10:27:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9614856</guid><dc:creator>DotNetShoutout</dc:creator><description>&lt;p&gt;Thank you for submitting this cool story - Trackback from DotNetShoutout&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9615072</link><pubDate>Thu, 14 May 2009 11:01:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9615072</guid><dc:creator>Muhammad Mosa</dc:creator><description>&lt;p&gt;As this going to support Linq, the return type of Fucntions that return collection would be of type IQueryable right?&lt;/p&gt;
&lt;p&gt;Also in case function return colletion of entities does eager and lazy loading work on this case?!&lt;/p&gt;
&lt;p&gt;I also assume it will support POCO entities by default! Am I right?&lt;/p&gt;
</description></item><item><title>Entity Framework: функции определенные в модели</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9615907</link><pubDate>Thu, 14 May 2009 16:21:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9615907</guid><dc:creator>progg.ru</dc:creator><description>&lt;p&gt;Thank you for submitting this cool story - Trackback from progg.ru&lt;/p&gt;
</description></item><item><title>re: Model Defined Functions</title><link>http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx#9616122</link><pubDate>Thu, 14 May 2009 17:31:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9616122</guid><dc:creator>Daniel Simmons</dc:creator><description>&lt;p&gt;@Muhammad,&lt;/p&gt;
&lt;p&gt;These functions are just used to give the function signature for us to figure out how to translate into a part of the overall query sent to the server. &amp;nbsp;As such the return type does not need to be IQueryable--it can be just IEnumerable.&lt;/p&gt;
&lt;p&gt;Once the query has been executed and the results returned, if the results are entities, then lazy loading will work the same as for any other entities. &amp;nbsp;Eager loading can also work because this is just a rewrite over the query to bring along extra data.&lt;/p&gt;
&lt;p&gt;Yes, it will work fine for whatever entities you have--POCO or non-POCO.&lt;/p&gt;
&lt;p&gt;- Danny&lt;/p&gt;
</description></item></channel></rss>