EF は、.net クラスをデータベースの構造と同期させることを得意としており、データベースが機能せず、すべてのロジックがクラス内にある場合に最適です。
ただし、関数とストアド プロシージャにマップすることはできます。説明するのは少し技術的です (はるかに簡単です)。リンクをいくつか見つけさせてください。
これを行う悪い方法は次のとおりです。
// Query that calls the OrderTotal function to recalculate the order total.
string queryString = @"USING Microsoft.Samples.Entity;
FUNCTION OrderTotal(o SalesOrderHeader) AS
(o.SubTotal + o.TaxAmt + o.Freight)
SELECT [order].TotalDue AS currentTotal, OrderTotal([order]) AS calculated
FROM AdventureWorksEntities.SalesOrderHeaders AS [order]
WHERE [order].Contact.ContactID = @customer";
int customerId = 364;
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
ObjectQuery<DbDataRecord> query = new ObjectQuery<DbDataRecord>(queryString, context);
query.Parameters.Add(new ObjectParameter("customer",customerId));
foreach (DbDataRecord rec in query)
{
Console.WriteLine("Order Total: Current - {0}, Calculated - {1}.",
rec[0], rec[1]);
}
}
http://msdn.microsoft.com/en-us/library/dd490951.aspx
適切に行う方法は次のとおりです。
http://scipbe.wordpress.com/2010/08/30/stored-procedures-udfs-in-the-entity-framework-part-1/