问题描述
classA:ActiveRecordBase{publicintAID{get;set;}publicintANAME{get;set;}}classB:ActiveRecordBase{publicintAID{get;set;}publicintBID{get;set;}publicintBNAME{get;set;}}classC:ActiveRecordBase{publicintAID{get;set;}publicintCID{get;set;}publicintCNAME{get;set;}}A->B,A->C全是一对多的关系。条件:如果满足BID=3(某一指定的值)或者CID=5的所有A数据如何来写。
解决方案
本帖最后由 chybaby 于 2011-12-19 13:17:00 编辑
解决方案二:
该回复于2011-12-19 13:54:07被版主删除
解决方案三:
List<A>.Where(a=>List<C>.Where(c=>c.CID==5).Contains(a.AID))
解决方案四:
引用2楼sandy945的回复:
List<A>.Where(a=>List<C>.Where(c=>c.CID==5).Contains(a.AID))
+1
解决方案五:
privatevoidbutton1_Click(objectsender,EventArgse){Aa1=newA();Aa2=newA();Bb1=newB();Bb2=newB();Bb3=newB();Bb4=newB();Cc1=newC();Cc2=newC();Cc3=newC();Cc4=newC();a1.AID=1;a1.ANAME=1;a2.AID=2;a2.AID=2;b1.AID=1;b1.BID=1;b1.BNAME=1;b2.AID=1;b2.BID=2;b2.BNAME=2;b3.AID=2;b3.BID=3;b3.BNAME=3;b4.AID=2;b4.BID=4;b4.BNAME=4;c1.AID=1;c1.CID=1;c1.CNAME=1;c2.AID=1;c2.CID=2;c2.CNAME=2;c3.AID=2;c3.CID=3;c3.CNAME=3;c4.AID=2;c4.CID=4;c4.CNAME=4;Managermanager=newManager();manager.InsertA(refa1);manager.InsertA(refa2);manager.InsertB(refb1);manager.InsertB(refb2);manager.InsertB(refb3);manager.InsertB(refb4);manager.InsertC(refc1);manager.InsertC(refc2);manager.InsertC(refc3);manager.InsertC(refc4);List<A>listA=manager.GetByBID(1);foreach(AainlistA){MessageBox.Show(a.AID.ToString());}}}}classActiveRecordBase{}classA:ActiveRecordBase{publicintAID{get;set;}publicintANAME{get;set;}}classB:ActiveRecordBase{publicintAID{get;set;}publicintBID{get;set;}publicintBNAME{get;set;}}classC:ActiveRecordBase{publicintAID{get;set;}publicintCID{get;set;}publicintCNAME{get;set;}}classManager{privateList<A>listA=null;privateList<B>listB=null;privateList<C>listC=null;publicManager(){listA=newList<A>();listB=newList<B>();listC=newList<C>();}~Manager(){listA.Clear();listB.Clear();listC.Clear();}publicvoidInsertA(refAa){listA.Add(a);}publicvoidInsertB(refBb){listB.Add(b);}publicvoidInsertC(refCc){listC.Add(c);}publicList<A>GetByBID(intID){varlistAnonymousTypes=(frombain(frombinlistBwhereb.BID==IDselectb.AID).ToList()fromainlistAwherea.AID==baselecta).ToList();returnlistAnonymousTypes;}}