2016-11-08 3 views
0

私は、ストアドプロシージャに変更する必要があるlinq式があります。 このlinq式は、dbml(テーブル)から定義されたオブジェクトを返します。オブジェクトをLinqのストアドプロシージャから返す

私は私のストアドプロシージャ(私はSP_testResult配列を返します)と私はそれがオブジェクトとして定義されたテーブルを返すようにしたいと思います。

dbmlのSPの戻り値の型を変更した場合、結果を確認しても何も返されませんが、SPを単独で実行すると、返されます。

返品の種類を定義する方法はありますか? SP_testはClientオブジェクトを返しますか? (それは私のdbmlモデルのテーブルです)、または私はSP_testResultをClientオブジェクトにマップする必要がありますか?これに

this.bookings = db.Bookings 
     .FilterUser(_main.Identity.GetUser()) 
     .Where(x => x.ProductId == PackageContent.ProductId && x.CampaignId == PackageContent.CampaignId && x.ClientId == PackageContent.ClientId) 
     .Where(x => Math.Abs((x.DateCreated - PackageContent.DateCreated).Days) < daysRange) 
     .ToList() 
     .Union(db.Bookings.Where(x => PackageContent.ExternCode == x.BussinessRefernce)) 
     .OrderBy(x => x.DateCreated); 

:私はこれから行きたい

どちらの場合も

this.bookings = db.SP_SearchSimilarBookings.toList(); 

、this.bookingsは予約クラスからの配列です。

+0

あなたのコードを表示してください。 – sr28

+0

codEはどこですか? ! – mybirthname

+0

申し訳ありませんが、コード –

答えて

0

おそらく、あなたのカスタムオブジェクトへのあなたのSPの結果をマップするために、このような何かを行うことを検討:

//create your connection string 
string Conn = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; 

using (SqlConnection connection = new SqlConnection(Conn)) 
{ 
    //add your SP to the SqlCommand 
    SqlCommand cmd = new SqlCommand("dbo.MyProcedure", connection); 
    cmd.CommandType = CommandType.StoredProcedure; 

    SqlParameter myParam = new SqlParameter("@YourParam", //Your SqlDbType); 
    myParam.Value = //your value; 
    cmd.Parameters.Add(myParam); 

    //Add more parameters if applicable... 

    SqlDataReader dr = command.ExecuteReader(); 

    if (dr.HasRows) 
    { 
     while (dr.Read()) 
     { 
      //map to your custom object here by instantiating one and mapping 
      //the SqlDataReader columns to your custom object properties. 
     } 
    } 
} 
関連する問題