2010-02-04 16 views
1

간단한 예를 들자면 : 고객 테이블과 고객 테이블이 모두있는 고객 테이블과 계좌 테이블을 가지고 있습니다 :Linq to SQL : 여러 테이블의 데이터가있는 formview를 어떻게 업데이트 할 수 있습니까?

두 테이블의 데이터를 업데이트 할 수있는 formview 싶습니다.

FormView :

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

가 어떻게 LINQ to SQL은이 작업을 수행 할 수 있습니까? Bind ("Account.AccountRate")와 같은 Bind 문을 사용합니까? 아니면 ItemUpdating 이벤트 또는 이와 유사한 마법을해야합니까?

답변

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} 

당신이 어딘가에 클래스로 모델링하고 그 결합 정의에 가입해야합니다.

+0

다음으로 formview에 바인드하기 위해 objectdatasource를 사용하겠습니까? 아니면 linqdatasource로 할 수 있습니까? – User

1

I'am는 SQL에 LINQ와 함께 작동하지 않습니다,하지만 엔티티 프레임 워크에 나는 같은 것을 할 필요가 : 내가로부터 속성을 검색하는 일부 성공을 거두었습니다

0

이 도움말을 희망

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; 

First Name: 
<asp:TextBox ID="FirstNameTextBox" runat="server" 
Text='<%# Bind("Entitycontact.Namefirst") %>' />