我所做的是創建一個顯示類,將linq以sql表對象作爲參數傳遞給構造函數,然後僅包裝我想要顯示的屬性。例如,下面的類,我想允許編輯街道和城市,但也顯示應用程序數量和狀態:
public class AddressDisplay
{
private Retailer _retailer;
private BusinessAddress _address;
public AddressDisplay(Retailer retailer, BusinessAddress address)
{
_retailer = retailer;
_address = address;
}
public string ApplicationNumber
{
get { return _retailer.ApplicationNumber; }
}
public string Status
{
get { return _retailer.Status; }
}
public string Street
{
get { return _address.Street1; }
set { _address.Street1 = value; }
}
public string City
{
get { return _address.City; }
set { _address.City = value; }
}
}
,然後返回實例AddressDisplay
綁定到DataGridView
:
var addresses = from a in _context.BusinessAddresses
join r in _context.Retailers on a.ApplicationNumber equals r.ApplicationNumber
where a.City == city
select new AddressDisplay(r, a);
HTH
神奇 - 完美的作品。非常感謝您的幫助! :-) – Dan 2010-11-01 13:19:57