在我的第一行代码中,我得到了所有可用的表单。
在第二行代码中我得到了所有签名的表单。
IEnumerable<ClinicForm> AllForms = db.ClinicForms.Where (d => d.ClinicId == clinicId); var SignedForms = db.SignedForms.Where (d => d.FormSigned == d.ClinicForm.Id && d.PatientId==patientId);这两行代码都可以正常工作,但我要做的是获取所有表单的列表,不包括任何已签名的表单。
我在这里做了几次尝试。
var test = from c in AllForms where !SignedForms.Contains(c.FormName) select c;此尝试导致错误:错误3'System.Collections.Generic.List.Contains(SDatabaseLibrary.SignedForm)'的最佳重载方法匹配具有一些无效参数
我的第二次尝试:
var test2 = from y in AllForms where !(from x in SignedForms where x.FormSigned==x.ClinicForm.Id && x.PatientId==patientId select x.ClinicForm).Contains(y.Id) select y;错误5实例参数:无法从'System.Collections.Generic.IEnumerable'转换为'System.Linq.IQueryable'
毫无疑问我错了,但我不知道在哪里。
In my first line of code I am getting all available forms.
In the second line of code I'm getting all signed forms.
IEnumerable<ClinicForm> AllForms = db.ClinicForms.Where (d => d.ClinicId == clinicId); var SignedForms = db.SignedForms.Where (d => d.FormSigned == d.ClinicForm.Id && d.PatientId==patientId);Both of these lines of code work fine, but what I'm trying to do is get the list of all forms excluding the any of the signed forms.
I've made several attempts here.
var test = from c in AllForms where !SignedForms.Contains(c.FormName) select c;This attempt results in an error: Error 3 The best overloaded method match for 'System.Collections.Generic.List.Contains(SDatabaseLibrary.SignedForm)' has some invalid arguments
My second attempt:
var test2 = from y in AllForms where !(from x in SignedForms where x.FormSigned==x.ClinicForm.Id && x.PatientId==patientId select x.ClinicForm).Contains(y.Id) select y;Error 5 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable'
No doubt I am casting something wrong, but I'm not sure where.
最满意答案
这是最终的工作解决方案,花了很多时间来实现它
var AllForms = db.ClinicForms.Where(d => d.ClinicId == clinicId); var SignedForms = AllForms.Where(d => d.SignedForm.FormSigned == d.Id && d.SignedForm.PatientId == patientId); var res = AllForms.Except(SignedForms);Here is the final working solution, took a lot of playing with to get it working
var AllForms = db.ClinicForms.Where(d => d.ClinicId == clinicId); var SignedForms = AllForms.Where(d => d.SignedForm.FormSigned == d.Id && d.SignedForm.PatientId == patientId); var res = AllForms.Except(SignedForms);linq从另一个结果集中排除(linq excluding one result set from another)在我的第一行代码中,我得到了所有可用的表单。
在第二行代码中我得到了所有签名的表单。
IEnumerable<ClinicForm> AllForms = db.ClinicForms.Where (d => d.ClinicId == clinicId); var SignedForms = db.SignedForms.Where (d => d.FormSigned == d.ClinicForm.Id && d.PatientId==patientId);这两行代码都可以正常工作,但我要做的是获取所有表单的列表,不包括任何已签名的表单。
我在这里做了几次尝试。
var test = from c in AllForms where !SignedForms.Contains(c.FormName) select c;此尝试导致错误:错误3'System.Collections.Generic.List.Contains(SDatabaseLibrary.SignedForm)'的最佳重载方法匹配具有一些无效参数
我的第二次尝试:
var test2 = from y in AllForms where !(from x in SignedForms where x.FormSigned==x.ClinicForm.Id && x.PatientId==patientId select x.ClinicForm).Contains(y.Id) select y;错误5实例参数:无法从'System.Collections.Generic.IEnumerable'转换为'System.Linq.IQueryable'
毫无疑问我错了,但我不知道在哪里。
In my first line of code I am getting all available forms.
In the second line of code I'm getting all signed forms.
IEnumerable<ClinicForm> AllForms = db.ClinicForms.Where (d => d.ClinicId == clinicId); var SignedForms = db.SignedForms.Where (d => d.FormSigned == d.ClinicForm.Id && d.PatientId==patientId);Both of these lines of code work fine, but what I'm trying to do is get the list of all forms excluding the any of the signed forms.
I've made several attempts here.
var test = from c in AllForms where !SignedForms.Contains(c.FormName) select c;This attempt results in an error: Error 3 The best overloaded method match for 'System.Collections.Generic.List.Contains(SDatabaseLibrary.SignedForm)' has some invalid arguments
My second attempt:
var test2 = from y in AllForms where !(from x in SignedForms where x.FormSigned==x.ClinicForm.Id && x.PatientId==patientId select x.ClinicForm).Contains(y.Id) select y;Error 5 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable'
No doubt I am casting something wrong, but I'm not sure where.
最满意答案
这是最终的工作解决方案,花了很多时间来实现它
var AllForms = db.ClinicForms.Where(d => d.ClinicId == clinicId); var SignedForms = AllForms.Where(d => d.SignedForm.FormSigned == d.Id && d.SignedForm.PatientId == patientId); var res = AllForms.Except(SignedForms);Here is the final working solution, took a lot of playing with to get it working
var AllForms = db.ClinicForms.Where(d => d.ClinicId == clinicId); var SignedForms = AllForms.Where(d => d.SignedForm.FormSigned == d.Id && d.SignedForm.PatientId == patientId); var res = AllForms.Except(SignedForms);
发布评论