我必须比较 UI 中的 IEnumerable 数据和 SQL Server 2008 中的 IEnumerable 数据,并且必须将新元素从 UI 插入/更新到 DB,并根据 UI 数据从 DB 中删除元素。
我在 DB 中有 Distribution_X_ListType 表为:
DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1 2 84528 NULL NULL
1 3 NULL 8051 NULL
1 5 NULL NULL 319
我在项目中有一个界面如下:
public interface IDistributionList : IEntity
{
string Name { get; set; }
bool ActiveFlag { get; set; }
...........................
...........................
IEnumerable<IDistributionListType> ListTypes { get; set; }
}
另一个界面是:
public interface IDistributionListType
{
int? DistributionID { get; set; }
int ListTypeID { get; set; }
int EmployeeNumber { get; set; }
int DepartmentID { get; set; }
int LocationID { get; set; }
}
在另一个项目中,我有如下保存功能:
public int Save(IDistributionList distributionList)
{
SqlDataReader reader = null;
int rowsaffected = 0;
try
{
sqlcommand = new SqlCommand("spGetDistributionListTypeByID", con); //spGetDistributionListTypeByID - This SP returns all the members from Distribution_X_ListType table for the given distribution ID
sqlcommand.CommandType = CommandType.StoredProcedure;
sqlcommand.Parameters.AddWithValue("@Distribution_ID", distributionList.ID);
reader = sqlcommand.ExecuteReader();
while (reader.Read())
{
????Value Should be stored in an IDistributionListType variable,say IDistributionListTypeFromDB
}
????IDistributionListType from function parameter(Lets say from UI) should be compared with the above IDistributionListTypeFromDB data.
????Insert/Delete should be done in DB by comparing the data.
}
}
让 IDistributionListType 的值来自 UI:
DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1 2 84528 NULL NULL
1 5 NULL NULL 64
让来自 DB 的 IDistributionListType 的值:
DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1 2 84528 NULL NULL
1 3 NULL 8051 NULL
1 5 NULL NULL 319
我需要使用 UI 中的数据更新数据库。我还有两个 SP:
spInsertUpdateDistributionListType - Insert/Update Distribution_X_ListType table based on DistributionID and listtypeID
spDeleteDistributionListType - Delete Distribution_X_ListType table based on DistributionID and listtypeID
不知道怎么打码???领域(在.net代码中提到)。任何人请帮忙。提前致谢。