我的問題似乎很簡單,但對我來說卻變得單調乏味。在我的項目中,我有一個充當數據訪問層的DBML文件。還有一種將現有結果轉換爲數據集的實用方法。下面是我的方法:將多個錶轉換爲數據集
#region To convert from LINQ to dataset
/// <summary>
/// Function convert linq to Dataset
/// </summary>
public static DataSet LINQToDataTable<T>(IEnumerable<T> varlist)
{
DataSet ds = new DataSet();
//Creating an object of datatable
DataTable dtReturn = new DataTable();
dtReturn.Rows.Clear();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return ds;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
ds.Tables.Add(dtReturn);
return ds;
}
#endregion
現在我的存儲過程中的一個具有運行從而從那裏返回三個表三種不同的選擇查詢。當我在後面的代碼上返回結果並快速觀察結果時,它給了我三個中唯一的一個表。
什麼是可能的解決方案。請幫助我。我認爲上述LOC可能存在一些問題。
SQL查詢,更新調用存儲過程
/// <summary>
///
/// </summary>
/// <returns></returns>
public DataSet GetTenantPropertyDetailsForAgreement(int tenantId, int propertyId,int billingPlanId)
{
DataSet ds = new DataSet();
try
{
using (objDataManagerDataContext = new DataManagerDataContext())
{
ds = Utility.LINQToDataTable(objDataManagerDataContext.usp_GetTenantPropertyDetailsForAgreement(tenantId,propertyId,billingPlanId));
}
}
catch (Exception ex)
{
SaveLogger.WriteError(ex.ToString());
}
return ds;
}
DBML文件的方法
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.usp_GetTenantPropertyDetailsForAgreement")]
public IEnumerable<usp_GetTenantPropertyDetailsForAgreementResult> usp_GetTenantPropertyDetailsForAgreement([global::System.Data.Linq.Mapping.ParameterAttribute(Name = "TenantId", DbType = "Int")] System.Nullable<int> tenantId, [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "PropertyDetailsId", DbType = "Int")] System.Nullable<int> propertyDetailsId, [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "BillingPlanId", DbType = "Int")] System.Nullable<int> billingPlanId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), tenantId, propertyDetailsId, billingPlanId);
return ((IEnumerable<usp_GetTenantPropertyDetailsForAgreementResult>)(result.ReturnValue));
}
你的存儲過程在哪裏?請將您的代碼發佈在您寫代碼的地方,以便致電SP –