如何使用来自SELECT
linq
WHERE
spesific_field
条IN
在SELECT
中撰写| absent | | lab | | time |
|———————————————| |———————————————| |———————————————|
|PK| absentID | ┌————|PK| labID | ┌————|PK| timeID |
| | date | | | | class_room | | | | start |
|FK| labID |———┘ | | timeID |—————┘ | | finish |
架构表
SELECT COUNT(*)
FROM absent
WHERE labID IN ( SELECT lab.labID
FROM lab INNER JOIN time
ON lab.timeID = time.timeID
WHERE lab.class_room = @class_room AND
time.start => getdate() and getdate() <= time.finish
如果它是用与此类似的查询代码编写的
[DataContract]
public class absent
{
[DataMember]
public int absentID { get; set; }
[DataMember]
public string name{ get; set; }
[DataMember]
public lab labID { get; set; }
}
}
[DataContract]
public class lab
{
[DataMember]
public int LabID{ get; set; }
[DataMember]
public string class_room { get; set; }
[DataMember]
public time timeID { get; set; }
}
}
[DataContract]
public class time
{
[DataMember]
public int timeID { get; set; }
[DataMember]
public DateTime start { get; set; }
[DataMember]
public DateTime finish{ get; set; }
}
}
[edit] [班级模特]
$('#upload-profile-button').on('click', function(e) {
$("#upload-profile-form").parsley().validate();
$("#upload-profile-form").parsley().on('form:validate', function (formInstance) {
var isFormValid = formInstance.isValid();
if(isFormValid){
e.preventDefault();
e.preventDefault();
$('#upload-profile-button').html('Uploading...');
var fd = new FormData($("#upload-profile-form")[0]);
$.ajax({
type : 'POST',
url : '/mbatch/batch/uploadBatch',
data : fd,
processData : false,
contentType : false,
beforeSend : function() {
},
success : function(response) {
if (response.data.fetchTpodSuccess == true) {
window.location.href= "/mbatch/batch/listBatch";
} else {
new PNotify({
title: 'Notice',
text: response.message,
type: 'error',
styling: 'bootstrap3'
});
$('#upload-profile-button').html('Submit');
}
},
error : function(data) {
new PNotify({
title: 'Notice',
text: JSON.parse(data.responseText).message,
type: 'error',
styling: 'bootstrap3'
});
$('#upload-profile-button').html('Submit');
}
});
}
});
});
答案 0 :(得分:0)
假设您已从db中检索了一个包含所有引用对象的完整模型,它看起来像您想要的那样:
string someClassRoom = null; //put classroom here
DateTime someDateTime = default(DateTime); //put date here
List<absent> absentCollection = null; //your collection or db table here
int count = absentCollection
.Where(abs =>
abs.labID.class_room == someClassRoom &&
abs.labID.timeID.start >= someDateTime &&
someDateTime <= abs.labID.timeID.finish)
.Count();