基于IEnumerable比较的操作 [英] Operations based on IEnumerable Comparison

查看:73
本文介绍了基于IEnumerable比较的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须比较来自UI的IEnumerable数据和来自SQL Server 2008的IEnumerable数据,并且必须将新元素从UI插入/更新到DB,并根据UI数据从DB中删除元素。



我在DB中有Distribution_X_ListType表格:



I have to compare the IEnumerable data from UI and the IEnumerable data from SQL Server 2008 and have to insert/update the new elements from UI to DB and delete the elements from DB based on UI data.

I am having Distribution_X_ListType table in DB as:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              3          NULL           8051         NULL
1              5          NULL           NULL         319



我是在项目中具有如下界面:




I am having an interface in a project as follows:

public interface IDistributionList : IEntity
    {
        string Name { get; set; }
        bool ActiveFlag { get; set; }
        ...........................
        ...........................
        IEnumerable<IDistributionListType> ListTypes { get; set; }
    }





另一个界面是:





The another interface is:

public interface IDistributionListType
{
    int? DistributionID { get; set; }
    int ListTypeID { get; set; }
    int EmployeeNumber { get; set; }
    int DepartmentID { get; set; }
    int LocationID { get; set; }
}





在另一个项目中,我有如下保存功能:





In another project I am having Save function as follows:

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.
             }
         }





从UI获取IDistributionListType的值:





Let the value of IDistributionListType from UI:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              5          NULL           NULL         64





从DB获取IDistributionListType的值:





Let the value of IDistributionListType from DB:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              3          NULL           8051         NULL
1              5          NULL           NULL         319





我需要使用UI中的数据更新数据库。我还有两个SP:





I need to update the DB with the data from UI. I am having two more SPs as :

spInsertUpdateDistributionListType - Insert/Update Distribution_X_ListType table  based on DistributionID and listtypeID
spDeleteDistributionListType - Delete Distribution_X_ListType table based on DistributionID and listtypeID





我不知道怎么编码?区域。有人请帮忙。在此先感谢。



I don''t know how to code in ???? areas. Anybody please helpout. Thanks in advance.

推荐答案

您必须拥有一个实现接口的具体类。您必须创建该类的对象并向其添加数据。然后可以将此对象添加到您拥有的接口列表中。
You must be having a concrete class that implements the interface. You will have to create object of that class and add data to it. This object can then be added to the interface list you have.


这篇关于基于IEnumerable比较的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆