complex query

Data Access Application Blocks Forum

complex query

Postby tenvick on Fri Jun 27, 2008 2:16 am

the sql query \"select count(*) from ReserveOrder where Convert(varchar(10),OrderTime,101) =Convert(varchar(10),@OrderTime,101) and (RealName = @RealName or TEl=@TEl)\"

the easyobject how to do that?
implssible is nothing
tenvick
Lurker
 
Posts: 9
Joined: Fri Aug 17, 2007 3:41 am

Postby mgnoonan on Fri Jun 27, 2008 3:30 pm

In this case, you are better off not using the dynamic query syntax and just writing your own custom load function in the concrete class, such as below.

Code: Select all
public int GetCount(DateTime OrderTime, string RealName, string TEl)
{
   string sqlCommand = \"select count(*) from \" + this.SchemaTableViewWithSeparator + this.TableName + \" where Convert(varchar(10),OrderTime,101) =Convert(varchar(10),@OrderTime,101) and (RealName = @RealName or TEl=@TEl)\";
   DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
   
   // Add procedure parameters (change the DbTypes to match your database)
   db.AddInParameter(dbCommand, \"OrderTime\", DbType.DateTime, OrderTime);
   db.AddInParameter(dbCommand, \"RealName\", DbType.AnsiString, RealName);
   db.AddInParameter(dbCommand, \"TEl\", DbType.AnsiString, TEl);
   
   // returns a bool if any rows loaded
   return (int)base.LoadFromSqlScalar(dbCommand);
}
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH


Return to EasyObjects.NET (Microsoft Enterprise Library)

Who is online

Users browsing this forum: No registered users and 1 guest

cron