我正在使用linq执行左外连接。右边的对象有42条记录,左边的对象有2条记录。结果应该是一个成功的连接,以及正确对象的剩余部分。
(代码后面出现错误信息。)
private async Task PopulateDatasourceOfPlanToKill()
{
_killPlansRepository = new KillPlansRepository();
_factoryRegistrations = new FactoryRegistrationsRepository();
var plans = _killPlansRepository.Get();
var registrations = _factoryRegistrations.GetTodaysRegistrations();
try
{
var query = plans.GroupJoin(
registrations, plan => plan.Id, reg => reg.PlanIdentity, (plan, reg) => new { killPlans = plan, registrations = reg})
.SelectMany(plan => plan.registrations.DefaultIfEmpty()
,(plan,Reg) => new
{
plan.killPlans.DateKilled
,plan.killPlans.FarmCode
,plan.killPlans.HouseNumber
,plan.killPlans.Quantity
,plan.killPlans.Age
,plan.killPlans.BirdSexCode
,plan.killPlans.EstimatedWeightG
,Reg.RegDateTime
});
var bob = new BindingSource();
bob.Add(query);
bsKillPlans.DataSource = bob;
//.OrderBy(r => r.FarmCode)
//.ThenByDescending(r => r.HouseNumber);
}
catch (Exception oops)
{
//Todo: logger
MessageBox.Show($"Can't load the daily kill plans. \rPlease contact the service desk on ???. \rTechnical: {oops.Message}");
}
}
返回的错误消息是:“对象引用未设置为对象的实例。”
帮助!