使用LINQ SQL就可以解決
create table [User] (ID int,name nvarchar(15),years int)
var result = from s in Users
orderby s.ID
select new {s.Name,s.years};
// @nuget: EntityFramework
// @nuget: Z.EntityFramework.Extensions
using System;
using System.Data.Entity;
using System.Linq;
using System.Collections.Generic;
using System.Linq.Dynamic;
public class Program
{
public static void Main()
{
InsertData();
using (var context = new EntityContext())
{
var result = from s in context.Users
orderby s.ID
select new {s.name,s.years};
};
}
public static void InsertData()
{
using (var context = new EntityContext())
{
context.BulkInsert(
new List<User>()
{
new User() { ID=1,name ="ITMan1",years=1},
new User() { ID=2,name ="ITMan2",years=2},
new User() { ID=3,name ="ITMan3",years=3}
}
);
}
}
public class EntityContext : DbContext
{
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
{
}
public DbSet<User> Users { get; set; }
}
public class User
{
public int ID { get; set; }
public string name { get; set; }
public int years { get; set; }
}
}