EntityFrameWork 查询视图问题
用EF想取出我在SQL中新建的视图中的所有数据,可是取出来的记录条数是对的,可数据都是第一条记录,请高手指教建立视图语句:createview[dbo].[View_In...
用EF想取出我在SQL中新建的视图中的所有数据,可是取出来的记录条数是对的,可数据都是第一条记录,请高手指教
建立视图语句:
create view [dbo].[View_InfractionRecordReport]
as
SELECT dbo.VehicleInfo.VehicleID,dbo.VehicleInfo.VehicleLicensePlate,dbo.VehicleInfo.DisplayedID,
dbo.JobInfo.TripStartOperatingTime,dbo.JobInfo.TripEndOperatingTime,dbo.JobInfo.LastVehicleLatitude,
dbo.JobInfo.LastVehicleLongitude,dbo.DriverInfo.DriverName,'' as [Date],
'' as [Hours],'' as [DrivingTime],'' as [StreetName]
FROM dbo.JobInfo
LEFT JOIN dbo.VehicleInfo ON dbo.VehicleInfo.VehicleID=dbo.JobInfo.VehicleID
LEFT JOIN dbo.DriverInfo ON dbo.DriverInfo.DriverID=dbo.JobInfo.DriverID
WHERE dbo.JobInfo.IsDeleted=0 and dbo.VehicleInfo.IsDeleted=0 and dbo.DriverInfo.IsDeleted=0 展开
建立视图语句:
create view [dbo].[View_InfractionRecordReport]
as
SELECT dbo.VehicleInfo.VehicleID,dbo.VehicleInfo.VehicleLicensePlate,dbo.VehicleInfo.DisplayedID,
dbo.JobInfo.TripStartOperatingTime,dbo.JobInfo.TripEndOperatingTime,dbo.JobInfo.LastVehicleLatitude,
dbo.JobInfo.LastVehicleLongitude,dbo.DriverInfo.DriverName,'' as [Date],
'' as [Hours],'' as [DrivingTime],'' as [StreetName]
FROM dbo.JobInfo
LEFT JOIN dbo.VehicleInfo ON dbo.VehicleInfo.VehicleID=dbo.JobInfo.VehicleID
LEFT JOIN dbo.DriverInfo ON dbo.DriverInfo.DriverID=dbo.JobInfo.DriverID
WHERE dbo.JobInfo.IsDeleted=0 and dbo.VehicleInfo.IsDeleted=0 and dbo.DriverInfo.IsDeleted=0 展开
1个回答
展开全部
using (MyDBEntities db = new MyDBEntities()) {
string sql = "Select * From View_InfractionRecordReport where 1 = 1";
return db.ExecuteStoreQuery<View_InfractionRecordReport>(sql).ToList()
}
这个是DataBase First方式 返回所有数据的。
如果是Code First
MyDbContext.View_InfractionRecordReport(sql).ToList();
MyDbContext.View_InfractionRecordReport.ToList();
这些方式应该都可以,不会只是第一条的,是不是你哪里查询弄错了,把相关代码查看一下吧
string sql = "Select * From View_InfractionRecordReport where 1 = 1";
return db.ExecuteStoreQuery<View_InfractionRecordReport>(sql).ToList()
}
这个是DataBase First方式 返回所有数据的。
如果是Code First
MyDbContext.View_InfractionRecordReport(sql).ToList();
MyDbContext.View_InfractionRecordReport.ToList();
这些方式应该都可以,不会只是第一条的,是不是你哪里查询弄错了,把相关代码查看一下吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询