先看看界面 asp.net MVC2 Jquery_第1张图片
这个界面的业务逻辑是:首先这是一个弹出层,用于修改或者添加新的信息。点击修改选中的行处第一列外均可编辑。如下
asp.net MVC2 Jquery_第2张图片
根据传递的批次信息,获取入学方式表的信息和学历层次表的信息。这样就有个问题,如果是添加,那么我把所有的入学方式和学历层次列出来,其他的全部用文本框。但是如果是修改,假如你取得是招生批次005相关的入学方式和学历层次信息。那么005没有关联的学历层次信息就不会显示在jqGrid中。这时候假如你想添加博士这个学历层次,岂不是实现不了。有的人说我绑定入学方式和学历层次信息,然后我再获取报名费,修业年限,通过后台传个json过来。太麻烦,我告诉你。这时候你应该想到的是外连接。看看我写的sql
/*获取入学信息*/
SELECT         dbo.entry_forms.name, dbo.entry_forms.entry_way_id, dbo.entry_forms_fee.*, dbo.admission_batchs.state,    
                                            dbo.admission_batchs.admission_batch_id    
FROM                 dbo.admission_batchs INNER JOIN
                                            dbo.entry_forms_fee ON dbo.admission_batchs.admission_batch_id = dbo.entry_forms_fee.admission_batch_id and dbo.admission_batchs.admission_batch_id='d05d35b09d4c4f958963f9bb21559334'    
                                            RIGHT OUTER JOIN
                                            dbo.entry_forms    ON dbo.entry_forms_fee.entry_way_id = dbo.entry_forms.entry_way_id
/*获取学历信息*/
SELECT         dbo.education_levels.education_id, dbo.education_levels.name, dbo.education_levels.type, dbo.education_levels.state,    
                                            dbo.educationlevel_claim.*, dbo.admission_batchs.admission_batch_id, dbo.admission_batchs.name,    
                                            dbo.admission_batchs.entry_way_date
FROM                 dbo.admission_batchs INNER JOIN
                                            dbo.educationlevel_claim ON dbo.admission_batchs.admission_batch_id = dbo.educationlevel_claim.admission_batch_id and dbo.admission_batchs.admission_batch_id='d05d35b09d4c4f958963f9bb21559334'
                                            RIGHT OUTER JOIN
                                            dbo.education_levels ON dbo.educationlevel_claim.education_id = dbo.education_levels.education_id
但是哥们现在用的是EF,只能用linq,怎么办。直接整成linq就可以啊。
from entryForms in admissionBatchsEntities.entry_forms
                                                     from admissionBatchs in admissionBatchsEntities.admission_batchs
                                                     where admissionBatchs.admission_batch_id == admissionBatchId
                                                     join ef in admissionBatchsEntities.entry_forms_fee
                                                     on new
                                                     {
                                                             entryForms.entry_way_id,
                                                             admissionBatchs.admission_batch_id
                                                     } equals
                                                     new
                                                     {
                                                             ef.entry_way_id,
                                                             ef.admission_batch_id
                                                     }
                                                     into temptable
                                                     from temp in temptable.DefaultIfEmpty()
                                                     select new
                                                     {
                                                             entryWayId = entryForms.entry_way_id,
                                                             entryWayName = entryForms.name,
                                                             admissionBatchId = temp.admission_batch_id,
                                                             entryFee = temp.entry_fee,
                                                             testFee = temp.test_fee
                                                     }
我只翻译一个啊,两个都是这样的写法。最后得到的结果是
asp.net MVC2 Jquery_第3张图片