C# 从强类型数据集中获取一行而不获取who表

C# 从强类型数据集中获取一行而不获取who表,c#,sql-server,strongly-typed-dataset,C#,Sql Server,Strongly Typed Dataset,我目前有以下代码: /// <summary> /// This is an ineffecient method of getting a tenant by their id. /// </summary> /// <param name="id">int ID of the tenant to be selected</param> /// <returns>Tenant with the s

我目前有以下代码:

   /// <summary>
    /// This is an ineffecient method of getting a tenant by their id.
    /// </summary>
    /// <param name="id">int ID of the tenant to be selected</param>
    /// <returns>Tenant with the specific ID, or null if not found.</returns>
    public static Tenant GetTenantByID(int id){
        RentalEaseDataSetTableAdapters.tblTenantTableAdapter adapter = new RentalEaseLogic.Database.RentalEaseDataSetTableAdapters.tblTenantTableAdapter();
        RentalEaseDataSet ds = new RentalEaseDataSet();

        adapter.Fill(ds.tblTenant);

        DataRow[] rows = ds.tblTenant.Select("ID = " + id);

        if (rows.Length > 0) {
            return new Tenant(rows[0] as RentalEaseDataSet.tblTenantRow);
        } else {
            return null;
        }
    }
//
///这是一种通过身份证获取租户的无效方法。
/// 
///要选择的租户的int ID
///具有特定ID的租户,如果找不到,则为null。
公共静态租户GetTenantByID(int-id){
RentalEaseDataSetTableAdapters.tblTenantTableAdapter=新的RentalEaseLogic.Database.RentalEaseDataSetTableAdapters.tblTenantTableAdapter();
RentalEaseDataSet ds=新的RentalEaseDataSet();
适配器填充(ds.tblTenant);
DataRow[]rows=ds.tblTenant.Select(“ID=”+ID);
如果(rows.Length>0){
返回新租户(行[0]为RentalEaseDataSet.tblTenantRow);
}否则{
返回null;
}
}
这在性能上相当糟糕。每当有人想要一排时,它就会抓起并装入一张大桌子。一定有更好的办法


如何从一个表中选择一行,而不必填充整个表,并且仍然保持强数据类型?

有。将查询与您的
表格适配器关联。主要是

然后用查询的行填充数据集