EF中使用SqlQuery执行语句

            string sql = @"
                        SELECT     B.[FId], 
                                A.[FileTypeNo], 
                                A.[FtypeName], 
                                A.[FtypeId], 
                                A.[ProcessName],
                                A.[ProcessId],
                                B.[InstanceId],
                                B.[Status]
                        FROM    [Process] AS A
                        INNER   JOIN [ProcessInstance] AS B ON A.[ProcessId]=B.[ProcessId]
                        WHERE   B.[UserId]=@userId AND A.[FileTypeNo]=@FileTypeNo";
            using(DbHelper<Process> pDb = new DbHelper<Process>())
            {
                var userNameParam = new System.Data.SqlClient.SqlParameter
                {
                    ParameterName = "@userId",
                    Value = userId
                };
                var fileTypeNoParam = new System.Data.SqlClient.SqlParameter
                {
                    ParameterName = "@fileTypeNo",
                    Value = fileTypeNo
                };
                var info = pDb.Database.SqlQuery<ProcessAllInfoDto>(sql, userNameParam, fileTypeNoParam).FirstOrDefault();
                return info;
            }

 

posted @ 2018-08-06 15:05  HandsomeBoy  阅读(5151)  评论(0编辑  收藏  举报