参数对象化,怎样用linq拼SQL?该怎么处理
参数对象化,怎样用linq拼SQL????public class NewsTitleSearchCondition{/// /// 开始日期///
参数对象化,怎样用linq拼SQL????
public class NewsTitleSearchCondition
{
/// <summary>
/// 开始日期
/// </summary>
[DataMember]
public DateTime StarDate { get; set; }
/// <summary>
/// 结束日期日期
/// </summary>
[DataMember]
public DateTime EndDate { get; set; }
/// <summary>
/// 标题
/// </summary>
[DataMember]
public string Title { get; set; }
}
//用对象拼出SQL,SQL条件为OR
private string GetSelectCommand(NewsTitleSearchCondition condition)
{
string sql="select * from AA"
//SQL+condition对象。。(用linq咋写呀??)
}
同事给一段代码,叫我参照参照,琢磨了一下,没看懂!!
代码如下:
public class k
{
public void hh(SearchCondition condition)
{
Type t= typeof( condition);
System.Reflection.PropertyInfo[] g= t.GetProperties (condition);
var query = from item in g
select new ConditionField
{
Name=item.Name ,
Value = string.Empty + item.GetValue(condition),
};
string sql = " sss where ";
foreach (ConditionField ini in query)
{
ini.Name
ini.Value
sql+= ini.Name like ini.Value
}
sql
}
}
[解决办法] http://blog.csdn.net/q107770540/article/details/5724013