1

举个简单的例子:

我有一个带有 customerID 字段的客户表和一个帐户表。我想要可以更新两个表中的数据的表单视图。

窗体视图:

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,但在实体框架中我需要做这样的事情:

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 回答