日期:2014-05-20  浏览次数:20796 次

Entity Framework中怎么将自定义SQL语句的结果插在自定义类型中
刚开始用Entity Framework,
我的代码
C# code
            
using (MTSEntities entities = new MTSEntities())
            {
                string queryStr = @"select b.UserName as UserName,
                                    SqlServer.AVG(SqlServer.DATEDIFF('year', a.BirthDay, SqlServer.getDate())) as ArgAge 
                                    from MTS_CaseInfo as a inner join MTS_Doctor as b
                                    on a.Account = b.Account group by b.UserName";
                ObjectQuery<ReportGender> query = entities.CreateQuery<ReportGender>
                    (queryStr);


我知道.net framework 4.0下好像有个ExecuteStoreQuery的方法,但我用的是3.5并没有这个方法

另询问类似DATEDIFF这样的SqlServer函数在Linq里该怎么写。

------解决方案--------------------
使用 ExecuteQuery()方法
------解决方案--------------------
http://www.cnblogs.com/snowdream/archive/2008/07/18/1246308.html
------解决方案--------------------
哎,与这样用linq, 不如老老实实用ado.net
------解决方案--------------------
SqlMethods.DateDiffMonth(i.DateStart, i.DateEnd);
System.Data.Linq.SqlClient.SqlMethods.DateDiffDay(v.DateStart, DateTime.Now) < 0
 

------解决方案--------------------
探讨
SqlMethods.DateDiffMonth(i.DateStart, i.DateEnd);
System.Data.Linq.SqlClient.SqlMethods.DateDiffDay(v.DateStart, DateTime.Now) < 0

------解决方案--------------------
3.5 
ObjectQuery<ReportGender> query = entities.CreateQuery<ReportGender>
(queryStr);
ojbectResult<ReportGender> result = entities.Execute(MergeOption.NoTracking);
------解决方案--------------------
探讨

http://www.cnblogs.com/snowdream/archive/2008/07/18/1246308.html