|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlTypes;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LinqStudy.Test.LinqToObject
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 转换运算符
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TypeConvertTest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AsEnumeralbe:
|
|
|
|
|
/// System.Linq.Enumeralbe中,扩展方法
|
|
|
|
|
/// AsEnumeralbe() 是延迟执行
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AsEnumeralbe_Test()
|
|
|
|
|
{
|
|
|
|
|
DataTable dt=new DataTable();
|
|
|
|
|
DataColumn col_id=new DataColumn("Id");
|
|
|
|
|
col_id.AllowDBNull=false;
|
|
|
|
|
col_id.AutoIncrementSeed=1;
|
|
|
|
|
col_id.AutoIncrement=true;
|
|
|
|
|
col_id.AutoIncrementStep=1;
|
|
|
|
|
col_id.DataType=typeof(int);
|
|
|
|
|
|
|
|
|
|
DataColumn col_name=new DataColumn("Name");
|
|
|
|
|
col_name.AllowDBNull=true;
|
|
|
|
|
col_name.AutoIncrement=false;
|
|
|
|
|
col_name.DataType=typeof(string);
|
|
|
|
|
col_name.DefaultValue=string.Empty;
|
|
|
|
|
|
|
|
|
|
DataColumn col_age=new DataColumn("Age");
|
|
|
|
|
col_age.AllowDBNull=false;
|
|
|
|
|
col_age.AutoIncrement=false;
|
|
|
|
|
col_age.DataType=typeof(int);
|
|
|
|
|
col_age.DefaultValue=20;
|
|
|
|
|
|
|
|
|
|
dt.Columns.Add(col_id);
|
|
|
|
|
dt.Columns.Add(col_name);
|
|
|
|
|
dt.Columns.Add(col_age);
|
|
|
|
|
|
|
|
|
|
var row_one = dt.NewRow();
|
|
|
|
|
row_one[1]="王高峰";
|
|
|
|
|
row_one[2]=21;
|
|
|
|
|
|
|
|
|
|
dt.Rows.Add(row_one);
|
|
|
|
|
|
|
|
|
|
var cc = from row in dt.Select()
|
|
|
|
|
select row;
|
|
|
|
|
var dd = cc.ToList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 1.IEnumeralbe 转换为 IQueryable
|
|
|
|
|
/// 2.IEnumeralbe<T> 转换为 IQueryable<T>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AsQueryable_Test()
|
|
|
|
|
{
|
|
|
|
|
IEnumerable bb= Enumerable.Range(1,100);
|
|
|
|
|
|
|
|
|
|
var cc=bb.AsQueryable();
|
|
|
|
|
|
|
|
|
|
int[] t=new int[]{1,2,3};
|
|
|
|
|
|
|
|
|
|
t.AsEnumerable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|