C# 返回错误的列表。我能退另一个吗?

C# 返回错误的列表。我能退另一个吗?,c#,list,mvvm,observablecollection,C#,List,Mvvm,Observablecollection,好的,我的WPF应用程序中有一个gridview。我使用MVVM和C。gridview中充满了数据。 我使用web服务调用数据。我不直接与数据库通信。我们已经设置了存储过程,所以我无法创建自己的存储过程并将其用于应用程序 我有两张桌子。MaintenanceCall和MainCallProblems,MaintenanceCall的孩子 维修呼叫: [Intrecno] [bigint] IDENTITY(1,1) NOT NULL, [IntrecnoLandObject] [bigint]

好的,我的WPF应用程序中有一个gridview。我使用MVVM和C。gridview中充满了数据。 我使用web服务调用数据。我不直接与数据库通信。我们已经设置了存储过程,所以我无法创建自己的存储过程并将其用于应用程序

我有两张桌子。MaintenanceCall和MainCallProblems,MaintenanceCall的孩子 维修呼叫:

[Intrecno] [bigint] IDENTITY(1,1) NOT NULL,
[IntrecnoLandObject] [bigint] NULL,
[CallerName] [varchar](100) NULL,
[CallerTel] [varchar](20) NULL,
[CaptureBy] [bigint] NULL,
[CaptureDate] [datetime] NULL,
Intrecno是PK。IntrecnoLandObject是一个FK,我将使用它来提取数据

主要问题:

[Intrecno] [bigint] IDENTITY(1,1) NOT NULL,
[IntrecnoCallNo] [bigint] NULL,
[CaptureBy] [bigint] NULL,
[CaptureDate] [datetime] NULL,
[ProblemDescription] [varchar](500) NULL,
IntrecnoCallNo是来自MaintenanceCall的FK

基本上,用户使用我的表单在对象上记录投诉/问题。他选择对象,将其ID存储在内存中并记录调用。每个电话都可能有很多问题。单击save(保存)后,通话将被记录。数据将插入MaintenanceCall、对象ID、记录调用的用户和时间。然后该问题与用户等一起登录到MainCallProblems。。。只需知道所有字段都已填写

现在我的表单上有一个历史网格视图。当用户选择要记录调用的对象时,应该加载历史记录(如果有)。 这是我的问题

在我的服务代码的某个地方,我把错误的列表放在了某个地方。 假设有4个MaintenanceCall记录。在MainCallProblems中,每个MainCall都有自己的问题。如果一个电话有两个问题怎么办?这就是我一直坚持的

填充并发送回列表的我的服务代码:

 public List<MaintenanceCall> GetMaintenance(Dictionary<string, object> propertyValues) //Brings in the selected land object intrecno number
    {
        List<MaintenanceCall> mainCalls = ExecuteDataReader<MaintenanceCall>("spGetMainCall", propertyValues, typeof(MaintenanceCall)); //finds all maintenance calls associated with that land object
        foreach (var instance in mainCalls) //for each specific call
        {
            Dictionary<string, object> paramKey = new Dictionary<string, object>();
            paramKey.Add("IntrecnoCallNo", instance.Intrecno); //now sends the primary key of maintenance call into the child table, MainCallProblems and finds the problems with that key, which is the foreign key 

            List<MainCallProblems> problems = ExecuteDataReader<MainCallProblems>("spGetMainCallProblems", paramKey, typeof(MainCallProblems)); //creates a list of the problems associated with that call. can be one or many

            foreach (var problem in problems) //for each problem with that call, fill out the data
            {
                instance.ProblemDesc = problem.ProblemDescription; // the problem description for each problem call
            }
        }

        return mainCalls; //returns the first list, with the data now stored
    }
public List GetMaintenance(Dictionary propertyvalue)//引入所选的土地对象intrecno编号
{
List mainCalls=ExecuteDataReader(“spGetMainCall”,PropertyValue,typeof(MaintenanceCall));//查找与该land对象关联的所有维护调用
foreach(mainCalls中的var实例)//用于每个特定调用
{
Dictionary paramKey=新字典();
paramKey.Add(“IntrecnoCallNo”,instance.Intrecno);//现在将维护调用的主键发送到子表MainCallProblems中,并查找该键的问题,该键是外键
List problems=ExecuteDataReader(“spGetMainCallProblems”,paramKey,typeof(MainCallProblems));//创建与该调用关联的问题列表。可以是一个或多个
foreach(problems中的var问题)//对于该调用的每个问题,填写数据
{
instance.ProblemDesc=problem.ProblemDescription;//每个问题调用的问题描述
}
}
return mainCalls;//返回第一个列表,现在存储数据
}
如您所见,我在方法params中获取landobject的ID。在存储过程中用于检索MaintenanceCall实例的。其中有4个

然后将每个调用分解为调用中的每个问题,即第一个foreach循环。现在MaintenanceCall的PK被传递到MainCallProblems中,以查找实际问题。 就像我说的,这个列表应该是5。 因此,返回的MaintenanceCall列表缺少一条记录。它填充数据并覆盖一条记录,因为一个列表比另一个列表小

我该如何纠正这一点。我无法使一个列表与另一个列表相同,我会出错。我不能返回任何其他列表类型

理想情况下,我希望返回:

如您所见,这只是我在SQL中编写的一个快速选择,它显示了FK和问题。2个问题有相同的FK,但在我的应用程序中,一个会被覆盖,我收到4个结果,而不是5个

如果需要进一步解释,请告诉我,我会相应地进行编辑。

明白了。 我创建了一个相同类型的新列表:
list callList=newlist()

在第二个循环中,在找到数据的地方,我填充了这个新列表:

callList.Add(new MaintenanceCall()
                {
                    ProblemDesc=instance.ProblemDesc
                });
我返回这个新列表,其中包含5个问题。它起作用了