1

簡単な例を見てみましょう。

両方ともcustomerIDフィールドを持つcustomerテーブルとaccountテーブルがあります。両方のテーブルのデータを更新できるformviewが必要です。

FormView:

First Name (Customer)
Last Name (Customer)
Address (Customer)
AccountRate (Account)

Linq to SQLでこれを行うにはどうすればよいですか?Bind( "Account.AccountRate")のようなBindステートメントを使用するだけですか?または、ItemUpdatingイベントなどで魔法をかける必要がありますか?

4

3 に答える 3

1

参加する必要があります

from c in db.Customer
join a in db.Account
on a.customerID equals c.customerID
select new Model {FirstName = c.firstName,LastName = c.lastName,Address = c.address,AccountRate = a.accountRate}

モデルをどこかのクラスとして定義し、それにバインドします。

于 2010-02-04T08:41:07.540 に答える
1

linq to SQLを使用することはありませんが、Entity Frameworkでは、次のような操作を行う必要があります。

protected void ObjectDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
        // Declaring the Entity context 
        AvalonEntities db = new AvalonEntities();

        // In updating méthod of a ObjectDataSource the "e" arg is my customer, so i grab this
        customer cus = (customer)e.InputParameters[0];


        // say that i have a DropDown to select the account ...
        // I Get de DropDown and get your SelectedValue.
        DropDownList ddlAccount  = (DropDownList)FormView1.FindControl("ddlAccount");
        // Whit the value i declare a new account
        account ac = new account () { id_account = int.Parse(ddlAccount.SelectedValue) };
        // and associate it to Customer
        cus.account = ac;

この助けを願っています

于 2010-02-05T10:59:55.597 に答える
0

次のように、リンクされたクラスからプロパティを取得することに成功しました。

First Name:
<asp:TextBox ID="FirstNameTextBox" runat="server"
 Text='<%# Bind("Entitycontact.Namefirst") %>' />
于 2010-07-02T14:32:04.710 に答える