BLL/extention/LinqToSqlExtensions.cs

(开头部分) 56KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Data.Common;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Runtime.CompilerServices;

namespace BLL.extention
{
	public static class LinqToSqlExtensions
	{
		/// <summary>
		/// Creates a *.csv file from an IQueryable query, dumping out the 'simple' properties/fields.
		/// </summary>
		/// <param name="query">Represents a SELECT query to execute.</param>
		/// <param name="fileName">The name of the file to create.</param>
		/// <remarks>
		/// <para>If the file specified by <paramref name="fileName"/> exists, it will be deleted.</para>
		/// <para>If the <paramref name="query"/> contains any properties that are entity sets (i.e. rows from a FK relationship) the values will not be dumped to the file.</para>
		/// <para>This method is useful for debugging purposes or when used in other utilities such as LINQPad.</para>
		/// </remarks>
		public static void DumpCSV( this IQueryable query, string fileName )
		{
			query.DumpCSV( fileName, true );
		}

		/// <summary>
		/// Creates a *.csv file from an IQueryable query, dumping out the 'simple' properties/fields.
		/// </summary>
		/// <param name="query">Represents a SELECT query to execute.</param>
		/// <param name="fileName">The name of the file to create.</param>
		/// <param name="deleteFile">Whether or not to delete the file specified by <paramref name="fileName"/> if it exists.</param>
		/// <remarks>
		/// <para>If the <paramref name="query"/> contains any properties that are entity sets (i.e. rows from a FK relationship) the values will not be dumped to the file.</para>
		/// <para>This method is useful for debugging purposes or when used in other utilities such as LINQPad.</para>
		/// </remarks>
		public static void DumpCSV( this IQueryable query, string fileName, bool deleteFile )
		{
			if ( File.Exists( fileName ) && deleteFile )
			{
				File.Delete( fileName );
			}

			using ( var output = new FileStream( fileName, FileMode.CreateNew ) )
			{
				using ( var writer = new StreamWriter( output ) )
				{
					var firstRow = true;

					PropertyInfo[] properties = null;
					FieldInfo[] fields = null;
					Type type = null;
后面还有 1018 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。