090706 T Linq 的认识

时间:2022-04-24
本文章向大家介绍090706 T Linq 的认识,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
/// <summary>
/// 一个不错的Linq问题
/// </summary>
private void LinqQuestion()
{
    JZDataContext db = new JZDataContext();
    TextWriter log = new StringWriter();
    db.Log = log;  
    IEnumerable<A_User> table = db.A_Users;
    var q2 = table.Where(u => u.Id == 1);
    var users1 = q2.ToArray();
    Response.Write(log.ToString());
    //SELECT [t0].[Id], [t0].[HeadImagePath], [t0].[Gender], [t0].[DomainName], [t0].[ThemeNo], [t0].[SLOB_XML], [t0].[RealName], [t0].[Birthday], [t0].[StudyLevel], [t0].[SelfComment], [t0].[SidelineExperience], [t0].[SidelinesWantToDo], [t0].[SidelineTime], [t0].[SidelineCities], [t0].[MoneyWant], [t0].[Race], [t0].[Speciality], [t0].[HasGraduated], [t0].[CollegeId]
    //FROM [dbo].[A_Users] AS [t0]
    //-- Context: SqlProvider(Sql2000) Model: AttributedMetaModel Build: 3.5.30729.1  
    log = new StringWriter();
    db.Log = log;
    var q = db.A_Users.Where(u => u.Id == 1);
    var users2 = q.ToArray();
    Response.Write(log.ToString());
    //SELECT [t0].[Id], [t0].[HeadImagePath], [t0].[Gender], [t0].[DomainName], [t0].[ThemeNo], [t0].[SLOB_XML], [t0].[RealName], [t0].[Birthday], [t0].[StudyLevel], [t0].[SelfComment], [t0].[SidelineExperience], [t0].[SidelinesWantToDo], [t0].[SidelineTime], [t0].[SidelineCities], [t0].[MoneyWant], [t0].[Race], [t0].[Speciality], [t0].[HasGraduated], [t0].[CollegeId]
    //FROM [dbo].[A_Users] AS [t0]
    //WHERE [t0].[Id] = @p0
    //-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [1]
    //-- Context: SqlProvider(Sql2000) Model: AttributedMetaModel Build: 3.5.30729.1
}