小编Omi*_*-RH的帖子

如何管理多个OrderByDescending标准?

我想获得一个按优先级排序的三个属性的列表

  1. 至今
  2. RunDate

我的代码在这里

MyList
    .OrderByDescending(p => p.ToDate)
    .OrderByDescending(p => p.Number)
    .OrderByDescending(p => p.RunDate)
    .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

但结果不正确.

例如,当MyList包含两个元素:e1,e2和e1.ToDate> e2.ToDate时,结果为e2.

哪个属性应该先来?具有最高优先级(ToDate)或最低优先级(RunDate)的属性?

c# linq

11
推荐指数
1
解决办法
6358
查看次数

使用官方c#驱动程序在mongodb中保存具有双向关系的对象

我有两个这样的课:

public Class Company
{
    public IList<Employee> Employees;
}

public Class Employee
{
    public Company WorkPlace;
}
Run Code Online (Sandbox Code Playgroud)

当我想保存类公司的对象时:

MongoDatabase Database = MongoServer.GetDatabase("db");

var workPlace = new Company();

var employee = new Employee { WorkPalce = workPlace}    
workPlace.Employees = new List<Employee>{ employee };

Database.GetCollection<Company>("company").Save(workPlace);
Run Code Online (Sandbox Code Playgroud)

将抛出StackOverFlow异常.

c# stack-overflow mongodb bidirectional-relation mongodb-.net-driver

7
推荐指数
1
解决办法
2557
查看次数

如何通过名称获取实体的子属性

在类Person中我与类Position有关系,类Position与类PositionTitle有关系,而PositionTitle有一个名为Title的属性

public class Person
{
   public Position Position{get;set;}
}

public class Position
{
   public PositionTitle PositionTitle{get;set;}
}

public class PositionTitle 
{
   public string Title{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我有一个字符串"Person.Position.PositionTitle.Title",我怎么能用这个字符串得到这个人的属性?

c#

2
推荐指数
1
解决办法
603
查看次数