将两个列表分类为一个

时间:2013-03-04 04:32:12

标签: c# asp.net-mvc

嗨我有两个类,其中包含属性&我有一个类,其中包含两个类的列表作为其属性。我应该返回一个列表,其中包含在created_date.Can any1 help上排序的两个类的对象?我已经粘贴了以下3个类:

这是第一堂课: -

public partial class TouchPointModel : BaseModel
{
    public List<EntityModel> Entities { get; set; }
    public UserModel User { get; set; }
    public int TouchPointId { get; set; }
    public string Description { get; set; }
    public int EntityId { get; set; }
    public DateTime Created_date{ get;set; }
}

这是第二堂课: -

public partial class SurveyModel : BaseModel
{
    public int Id { get; set; }
    public int SelectedEntityId { get; set; }
    public int SelectedEntityType { get; set; }
    public int ParentEntityId { get; set; }
    public bool IsMyProjects { get; set; }
    public DateTime Created_date{ get;set; }
}

&安培;这是常见的类

public partial class RecentInteractionsModel
{
    public int ContactId { get; set; }
    public List<TouchPointModel> TouchPoints { get; set; }
    public List<SurveyModel> Surveys { get; set; }
    public int EntityId { get; set; }
    public int EntityTypeId { get; set; }
    public int SelectedParentId { get; set; }
}

对于UI,我应该根据创建的日期显示最新的接触点或调查。

1 个答案:

答案 0 :(得分:2)

听起来你需要Interface

之间的Classes
public interface IMyInterface
{
   DateTime Created_date{ get;set; }

   // add any other common properties between the 2 models

}


public partial class TouchPointModel : BaseModel, IMyInterface
{
   .......

   public DateTime Created_date{ get;set; }
}

public partial class SurveyModel : IMyInterface
{
   .......

   public DateTime Created_date{ get;set; }
}

然后您可以创建一个列表IMyInterface

List<IMyInterface> allItems = TouchPoints.Cast<IMyInterface>()
                       .Union(Surveys.Cast<IMyInterface>())
                       .OrderBy(x => x.Created_date).ToList();