Search
Closed
as By Design Help for as By Design

0
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 447865
Opened: 5/11/2009 7:55:46 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
ADO.NET Entity Frameworkでスカラ値ではないデータを返すストアドプロシージャを
利用した場合、通常のクエリの実行で、EntityCommandCompilationException例外が発生してしまう。

スカラ値ではないデータを返すストアドプロシージャを利用した場合でも、
通常のクエリが正しく動作するようにしてほしい。
Details (expand)
製品言語
日本語
バージョン
Visual Studio 2008 Service Pack 1
オペレーティング システム
Vista
オペレーティング システム言語
日本語
再現の手順
Northwndデータベースでの例
0.VS2008で、Northwndデータベースからデータモデルを作成する(詳細省略)
1.データモデルデザイナの画面で、空白部分を右クリックし、[データベースからモデルを更新(U)]を選択。
2.更新ウィザードの、[追加]タブで、利用したいストアドプロシージャ(CustOrderHist)にチェックを入れ、完了をクリック。
3.ストアドプロシージャ(CustOrderHist)が返すデータデータに合わせ、エンティティを作成する。
この例では、ProductNameとTotalプロパティを持つエンティティを作成
4.作成したエンティティを選択し、右クリックし、[追加(D)] - [関数インポート]をクリック。
5.関数インポートダイアログで、関数インポート名を入力し、OKを押す。
関数インポート名は、ストアドプロシージャと同名とする。
6.NorthwndEntitiesクラスに新しくメソッドCustOrderHistが追加されていることを確認
7.コードを書く
using (var db = new NorthwndEntities()) {
var results = db.CustOrderHist("ANATR");
foreach (var x in results)
Console.WriteLine("{0} {1}",x.ProductName, x.Total);
}
8.実行し、意図通りに動いていることを確認する。
9.通常のエンティティを参照するクエリを書く。
これはどんなクエリでも良い。
using (var db = new NorthwndEntities()) {
var query = from c in db.CustomerSet
where c.Fax != null
select c;
foreach (var c in query) {
Console.WriteLine("{0} {1}, {2}",
c.CustomerID, c.CompanyName, c.Fax);
}
}

10.このクエリを実行する。
11.EntityCommandCompilationException例外が発生する。
実際の結果
以下のような例外が発生する。
ハンドルされていない例外: System.Data.EntityCommandCompilationException: コマンド定義を準
備中にエラーが発生しました。詳細については、内部例外を参照してください。 ---> System.Data.
MappingException:
NorthwndModel.msl(3,4) : エラー 3027: 次の EntitySet または AssociationSet にマッピングが
指定されていません - OrderHistSet。
期待した結果
スカラ値ではないデータを返すストアドプロシージャを利用した場合でも、
通常のクエリが正しく動作するようにしてほしい。
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/12/2009 at 7:27 PM

この度は、フィードバックをお送りいただき、誠にありがとうございます。 現在、お送りいただきました報告内容に基づき問題を調査中ですので、しばらくお待ちください。 よろしくお願いいたします。

[Problem Description]
When you use a stored procedure that returns non-Scalar value data in the ADO.NET Entity Framework and run a normal query, EntityCommandCompilationException occurs.

Even when a stored procedure that returns non-Scalar value data is used, a normal query should function correctly.

[Repro Steps]
Here’s an example using a database “Northwind.”
0. Create a data model from Northwind on Visual Studio 2008 (details omitted).
1. Right-click at any empty place of the Data Model Designer window and select [Update Model from Database].
2. Open the [Add] tab of the Update Wizard, check the stored procedure you’d like to use (CustOrderHist), and click [Finish].
3. Create an entity according to the data returned from the stored procedure (CustOrderHist.) In this example, an entity with the ProductName and Total properties is created.
4. Select the entity created, right-click it, and click [Add (D)] > [Function Import].
5. Enter a function import name in the Add Function Import dialog box and click [OK]. The Function Import name is equal to the stored procedure.
6. Make sure the CustOrderHis method has been newly added to the NorthwindEntities class.
7. Write code.
using (var db = new NorthwindEntities()) {
var results = db.CustOrderHist("ANATR");
foreach (var x in results)
Console.WriteLine("{0} {1}",x.ProductName, x.Total);
}

8. Run and confirm it functions as intended.
9. Write a query to reference an entity. Any query will do.
using (var db = new NorthwindEntities()) {
var query = from c in db.CustomerSet
where c.Fax != null
select c;
foreach (var c in query) {
Console.WriteLine("{0} {1}, {2}",
c.CustomerID, c.CompanyName, c.Fax);
}
}

10. Run the query.
11. EntityCommandCompilationException occurs.

[Actual Results]
The below exception occurs.
Unhandled Exception: System.Data.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. --->
System.Data.
MappingException:
NorthwindModel.msl(3,4): error 3027: No mapping specified for the following EntitySet/AssociationSet – OrderHistSet.

[Expected Results]
Even when a stored procedure that returns non-Scalar value data is used, a normal query should function correctly.

Posted by Microsoft on 5/13/2009 at 3:49 AM
Thanks for reporting this issue. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 5/13/2009 at 5:58 PM

(こちらは、Posted by Microsoft on 5/13/2009 at 3:49 AM の和訳になります。)

問題をご報告いただき、ありがとうございます。 こちらのバグに関しましては、該当する機能を専門で担当している製品チームに報告させていただきます。 今後は、同チームが問題を再調査し、次期リリースでの修正について判断する予定です。 よろしくお願いいたします。

Visual Studio 製品チーム

Posted by Microsoft on 5/14/2009 at 4:10 PM
Thank you for filing this bug. This behavior is by design: Like all entities in a model, CustOrderHist must be mapped to at least one database table or view. In the model in this bug, CustOrderHist is not mapped - in fact, you should see an error in your error list complaining about this issue (although the project should still build and run.)

In the next release of the entity framework, you will be able to return complex types from stored procedures, which will enable this scenario. Until then, one workaround is to create a view in the model or in the database, and mapping the type to this view.
Posted by Microsoft on 5/15/2009 at 2:17 AM

(こちらは、Posted by Microsoft on 5/14/2009 at 4:10 PM の和訳です。)

バグをご報告いただき、ありがとうございます。 こちらの動作に関しましては、仕様となっています。 モデル内のすべてのエンティティと同様、CustOrderHist は、少なくとも1つのデータベース テーブルまたはビューにマップされなければなりません。 今回のバグのモデルでは、CustOrderHist がマップされていません。 おそらく、gushwell さんのエラー リストには、この問題を報告するエラーが記録されているはずです (プロジェクト自体はビルドおよび実行するのではないかと思いますが)。

Entity Framework の次期バージョンでは、ストアド プロシージャから複雑な型を返すことが可能になるため、このシナリオを実現することができるでしょう。 それまでの解決策の1つとしましては、モデルまたはデータベース内にビューを作成し、型をこのビューにマップする方法があります。