select * from [train] where id in(select trainid from [UserTrain] where userid='92' and trainid is not null);
------解决方案--------------------
------解决方案-------------------- var query=from t in db.train let temp=db.UserTrain.Where(u=>u.userid=="92" && !Nullable<int>.Equals(u.trainid,null)).Select(u=>u.trainid) where temp.Contains(t.id) select t;
------解决方案-------------------- FROM TB IN TABLE WHERE SELECT 语法这样 仿造语法自己改改吧 楼上也可以 18素材为你提供
------解决方案-------------------- IQueryable iqa=from t in db.Trains join ut in db.UserTrains on t.Id equals ut.TrainId where ut.UserId==92 &&ut.TrainId!=null select new{id=t.id,AliasName=t.AliasName};
------解决方案-------------------- IQueryable iqa=from t in db.Trains join ut in db.UserTrains on t.Id equals ut.TrainId where ut.UserId==92 &&ut.TrainId!=null select t; ddl_trainclass.DataSource = iqa.toList(); ddl_trainclass.DataBind(); ddl_trainclass.DataValueField = "id"; ddl_trainclass.DataTextField = "AliasName";