Txugo
Txugo

Reputation: 5078

Entity Framework - Model Defined Functions

I'm new to the Entity Framework.

I have a SQL Function that returns the age for a given birthday. (http://www.sql-server-helper.com/functions/get-age.aspx)

And I want to use it with linq. I know it's possible. I've read it here: http://blogs.msdn.com/efdesign/archive/2009/01/07/model-defined-functions.aspx http://blogs.msdn.com/efdesign/archive/2008/10/08/edm-and-store-functions-exposed-in-linq.aspx

but it seems this is part of the EF extentions (which I have) or that it is still in development.

Can anyone help me with this?

Thank you.

Upvotes: 0

Views: 1518

Answers (2)

Craig Stuntz
Craig Stuntz

Reputation: 126577

Model defined functions are not in the shipping Entity Framework, and I don't think they are in the extensions, either. As far as I know, they are a new feature planned for .NET 4.0. I don't know if they are in the Community Technology Preview of that. You can see a demo of model defined functions if you watch the Entity Framework presentation from PDC. But they are certainly not in .NET 3.5 SP1.

As a workaround, you could define a computed column on your table which used the function and then map that column instead of mapping the function directly.

Upvotes: 2

NikolaiDante
NikolaiDante

Reputation: 18649

You might be able to do a "FunctionImportMapping" see msdn for more info.. You could definitley do it that way if you exposed it as a sproc, I've not tried with just a function tho..

Upvotes: 1

Related Questions