public T Find<T>(int id) where T:BaseModel//给泛型添加约束
{
Type type=typeof(T);
//按SQL语法拼接获取到的数据库字段,格式为[{Id}],[{Name}].......
string columnString=string.Join(",",type.GetProperties().Select(p=>$"[{p.Name}]"));
string sql=$"SELECT{columnString} FROM [{type.Name}] WHERE Id={id}";
using(SqlConnection conn=new SqlConnection())
{
}
returun default(T);
}
C#字符串拼接,格式转换写法
最新推荐文章于 2024-01-19 15:37:13 发布