摘要: MEF 容器实例并非不可变的。如果目录支持改变(像监控目录变动)或者在运行时添加/移除部件都可能发生改变。以前,你不得不做出改动并且调用 CompositionContainer 上的 Compose 方法。在 Preview 4 release上,我们已经介绍对批量组合的支持。批处理包含一系列添加... 阅读全文
posted @ 2014-05-04 14:42 安布雷拉 阅读(879) 评论(0) 推荐(0) 编辑
摘要: CompositionContainer 公开了一部分获取导出、导出对象以及两者集合的重载。 在这些方法重载中,你应该遵循下面的共享行为准则 - 除非特别说明。 当请求单一实例的时候,如果没发现任何导入,将会抛出异常。 当请求单一实例的时候,如果发现不止一个导入,将会抛出异常。 ... 阅读全文
posted @ 2014-04-30 10:40 安布雷拉 阅读(2463) 评论(0) 推荐(0) 编辑
摘要: 有些应用程序被设计成在运行时动态地改变。例如,一个新的扩展可能被下载,或者其他原因变得不可用。MEF 依靠我们称之为重组(Composition)的技术处理,在初始化组合以后改变导入值的场景。导入可以通过 [System.ComponentModel.Composition.ImportAttrib... 阅读全文
posted @ 2014-04-28 17:06 安布雷拉 阅读(724) 评论(0) 推荐(0) 编辑
摘要: 理解 MEF 容器部件生命周期和实现是非常重要的事情。考虑到 MEF 关注可扩展应用程序。这变得尤为重要。生命期可以解释为期望部件的共享性(transitively, its exports) 共享,非共享与所有权(Share,Non Shared and ownership) 部件的共享... 阅读全文
posted @ 2014-04-25 16:51 安布雷拉 阅读(1064) 评论(0) 推荐(0) 编辑
摘要: 当使用子容器的时候,基于特定的标准(Specific Criteria)过滤目录是很必要的。比如,基于部件构造策略的过滤器是很常见的。下面的代码片段演示了如何构建的特殊途径(Particular Approach): var catalog = new AssemblyCatalog(typeof(... 阅读全文
posted @ 2014-04-23 23:34 安布雷拉 阅读(898) 评论(0) 推荐(0) 编辑
摘要: 目录(Catalogs)MEF 特性编程模型的核心价值,拥有通过目录动态地发现部件的能力。目录允许应用程序轻松地使用那些通过 Export Attribute 注册自身的导出。下面列出 MEF 提供的目录。程序集目录(Assembly Catalog)为了发现给定程序集所有导出,需要使用 [Syst... 阅读全文
posted @ 2014-04-22 14:36 安布雷拉 阅读(906) 评论(0) 推荐(0) 编辑
摘要: 声明导出解释了部件导出服务的基础知识和价值观(Values)。有时候出于种种原因,导出关联信息是非常必要的。通常,用于解释关于功能公共契约的具体实现。允许导入满足约束要求的导出,或者导入所有可用的实现并且在导出前在运行时检查他们的功能。为导出附加元数据(Attaching Metadata to a... 阅读全文
posted @ 2014-04-21 22:11 安布雷拉 阅读(1984) 评论(0) 推荐(0) 编辑
摘要: 在组合部件的时候,导入将会触发部件(部件集合)的实例化,为原始的请求部件公开必要的导出需求。对于有些应用程序,推迟实例化 - 并且防止递归组合图(Recursive Composition Down The Graph) - 因为创建长而复杂的对象图(Graph Of Object)的花费是昂贵和不... 阅读全文
posted @ 2014-04-19 15:03 安布雷拉 阅读(760) 评论(0) 推荐(0) 编辑
摘要: 组合部件通过 [System.ComponentModel.Composition.ImportAttribute] 特性声明导入。类似于导出,也有几种不同的方法声明导入,即通过:字段(Fields)、属性(Properties)和构造器参数(Constructor Parameters)。 ... 阅读全文
posted @ 2014-04-18 17:08 安布雷拉 阅读(803) 评论(0) 推荐(0) 编辑
摘要: 组合部件通过[System.ComponentModel.Composition.ExportAttribute] 特性声明导出。MEF 有几种不同的方式声明导出,包括在部件层面(Part Level),通过属性(Properties)和方法(Method)声明导出。 组合部件导出(Comp... 阅读全文
posted @ 2014-04-17 15:28 安布雷拉 阅读(1048) 评论(0) 推荐(0) 编辑
摘要: 可组合部件(Composable Parts)在 MEF 内部可组合部件是一个可组合单元。可组合部件导出其他可组合部件需要的服务,并且从其他可组合部件导入服务。在 MEF 编程模型中,可组合部件用 [System.ComponentModel.Composition.Import] 和 [Syste... 阅读全文
posted @ 2014-04-16 23:50 安布雷拉 阅读(1087) 评论(1) 推荐(0) 编辑
摘要: 在应用程序中托管(Hosing) MEF 涉及到创建组合容器(CompositionContainer) 实例,添加可组合部件(Composable Parts),包括应用程序宿主(Host)本身并进行组合(Composing)。下面是托管涉及的步骤。1.创建宿主(Host)类。下面的例子我们使用控... 阅读全文
posted @ 2014-04-15 14:29 安布雷拉 阅读(1351) 评论(1) 推荐(1) 编辑
摘要: 这是一个已经移植到 .NET 的 ADO 应用的例子。也演示了单向、只读、快速 DataReader 的使用。它演示如何使用 DataView 类从 DataSet 获取一个 Table 和 操作一个类似于旧的 ADO 记录集模型。请记得,ADO 记录集仅仅包含一个 Table 的数据,但是 ADO.NET DataSet 可以包含多个 Tables 并且非常灵活。原始的 ADO 示例使用 SQL Server 2000 下的 Employee 示例。原始的示例使用 ADO Recordset 对象管理从 SQL 查询返回的结果数据。新的示例演示了如何使用 SqlDataAdapter 填充 阅读全文
posted @ 2013-12-23 20:57 安布雷拉 阅读(1349) 评论(0) 推荐(0) 编辑
摘要: SqlDataReader 类提供了一种从数据源读取数据记录只进流的方法。如果想使用 OLE DB 接口的数据库或者 SQL Server7.0 之前的版本,请参考文章:使用 OLE DB 检索数据。SqlCommand 调用 ExecuteReader 方法创建 SqlDataReader,不通过直接使用构造器创建。当 SqlDataReader 正在使用时,关联的 SqlConnection 处于对 SqlDataReader 服务挂起状态。在这个状态下,除非关闭 SqlConnection 的连接,没有其他操作可以执行。在调用 SqlDataReader 的 Close 方法之前,会一直 阅读全文
posted @ 2013-12-01 21:33 安布雷拉 阅读(1123) 评论(0) 推荐(0) 编辑
摘要: OleDbDataReader 类提供了一种从数据源读取数据记录只进流的方法。如果想使用 SQL Server 7.0 或者更高版本,请参考文章:使用 SQL Server 检索数据。OleDbCommand 调用 ExecuteReader 方法创建 OleDbReader,不通过直接使用构造器创建。当 OleDbDataReader 正在使用时,关联的 OleDbConnection 处于对 OleDbDataReader 服务挂起状态。在这个状态下,除非关闭 OleDbConnection 的连接,没有其他操作可以执行。在调用 OleDbDataReader 的 Close 方法之前,会 阅读全文
posted @ 2013-11-28 23:01 安布雷拉 阅读(1388) 评论(0) 推荐(0) 编辑
摘要: 本文演示如何使用2种不同的方法从 SQL Server 生成 XML。方法1:使用了 SqlCommand 的 ExecuteXmlReader 方法获取 XmlReader,然后使用 DataSet 类的 ReadXml 方法把 XmlReader 填充到 DataSet。方法2:使用 SqlDataAdapter 提取数据内容,并使其适应 DataSet 内部的XML 结构。SqlDataAdapter 类封装了一组数据指令和一个数据连接,用于填充 DataSet 。示例1,首先打开一个 SQL Server Northwind 库的连接。然后创建 SqlCommand,从 Northwi 阅读全文
posted @ 2013-11-27 15:51 安布雷拉 阅读(1824) 评论(0) 推荐(0) 编辑
摘要: 这个示例演示了如何构建一个到数据源的连接池。你可以通过连接池部署高性能的应用程序。本例中使用连接串创建连接池,并且由 SqlConnection 自动管理。 string connString; connString = "server=(local);Integrated Security=SSPI;database=northwind;" + "pooling=true;"; SqlConnection myConnection = new SqlConnection(conn... 阅读全文
posted @ 2013-11-26 12:44 安布雷拉 阅读(1178) 评论(0) 推荐(0) 编辑
摘要: 我们有很多方法来过滤数据。一种是在数据库命令级别,利用 where 子句查询过滤数据。另一种是在数据填充到 DataSet 以后过滤数据。本篇讨论后者。一旦数据填充到 DataSet,你可以使用 DataSet 的方法获取一个数据子集。1、使用 Select 方法过滤设想一下 DataSet 填充了 Customers 和 Orders 两个表。你可以使用 Select 方法返回一组行,为名叫 Kelly 的 Customers 过滤数据。 myRowArray = dsCustomers.Select("ContactName like 'Kelly%'" 阅读全文
posted @ 2013-11-24 23:16 安布雷拉 阅读(1262) 评论(0) 推荐(1) 编辑
摘要: DataSet 可以包含非关联表,也可以包含关联表。你可以把 DataSet 想象成一个文档数据。事实上,除了 DataSet 是基于层级模型的,其它和 XML 数据文档是一样的。由于数据通常存储在关系数据库,DataSet 可以同时处理层级型关系和主键/外键型关系。 Relationships也有不同的执行方式。默认情况下,Deletes 和 Updates 是级联型的:假如删除一个 Customer 行,关联的 Orders 行也会被删除;假如更改一个 Customer 行的主键,关联的 Orders 表中的外键也会更改。DataSet 包含一个 Relations 集合。你可以利用关联表 阅读全文
posted @ 2013-11-23 15:29 安布雷拉 阅读(1340) 评论(0) 推荐(1) 编辑
摘要: 除了 Try/Catch 和 Exceptions 以外,新的 ADO.NET 数据框架也允许在 DataSet 的每行数据添加错误信息。如果 Updates 或者其他操作失败,SqlDataAdapters 为 Rows 附加上错误信息。此外,你可以过滤错误行呈现给用户,或者把它传递给错误处理函数。即使用 XML 或者 XML Web Services 传输,Errors 仍然伴随 DataSet。 你可以使用 RowError 属性为 DataSet 的 DataRow 设置错误信息。示例一: // 设置行的自定义错误 myDataSet.Tab... 阅读全文
posted @ 2013-11-22 14:07 安布雷拉 阅读(1383) 评论(0) 推荐(0) 编辑
摘要: 数据库事务用于控制数据提交到数据库。例如,在标准的账户程序,账户的借贷必须同时完成。由于电脑偶尔发生故障(电力中断、网络中断,等等),可能有些记录被更新或者添加,但是另外一些没有。为了避免这些情况,可以使用事务。ADO.NET 中的事务和 ADO 一样,是在数据库级别处理:即数据库必须支持事务。针对事务有三个基本命令:BeginTransaction、Commit、和 Rollback。BeginTransaction 标识着事务的开始。任何发生在 BeginTransaction 和下个命令(要么 Rollback 要么 Commit)都被认为是事务的一部分。下面的示例代码显示了使用 Sql 阅读全文
posted @ 2013-11-21 16:10 安布雷拉 阅读(1808) 评论(0) 推荐(2) 编辑
摘要: ADO.NET 和 DataSet 可以读写 XML Schema 和 XML。获取更多信息,请参考How do I...Use XML and the DataSet?DataSet 的 Schemas,或者 tables、columns、constraints 等等,可以用几种方式定义。一种方法是利用特性和方法创建他们(Tables.Add、Columns.Add、等等)。在 DataSet 内部建立了一个 Schema,可以作为容器保存数据。另一种方法是使用 SqlDataAdapter 或者 OleDbDataAdapter。当你使用这些命令,如果 DataSet 中的 Schema 阅读全文
posted @ 2013-11-20 14:56 安布雷拉 阅读(2256) 评论(0) 推荐(1) 编辑
摘要: 该主题说明了如何使用 DataSet 在数据库中更新数据。你依然可以直接使用 SqlCommand 在数据库中插入、更新、和删除数据,记住这一点也很重要。理解“从数据库填充DataSet”涵盖的概念有助于你理解这个主题。前一篇“从数据库填充 DataSet”涵盖的部分主题包括从数据库检索数据和填充到 DataSet,以及 DataSet 怎样有别于数据库。一旦 DataSet 被加载,你可以修改数据,并且DataSet 会跟踪变化。DataSet 可以被认为是从数据库检索出的在内存中的缓存数据。DataSet 包含一组表、关系、和约束。示例1中演示如何使用 Add 方法在 DataTable 阅读全文
posted @ 2013-11-19 18:40 安布雷拉 阅读(4969) 评论(0) 推荐(2) 编辑
摘要: 从数据库获取数据很容易,处理数据更容易。如果想要从数据库获取只进、只读的数据流结果集,你可以使用 DataReader 执行命令并且检索它。关于如何使用 DataReader,请参考:使用 OLE DB 检索数据、使用 SQL Server 检索数据。更多关于绑定、浏览、或者远程处理数据查询结果集的操作,你可以如下例所示把结果集放到 DataSet 里。请记住最重的是,DataSet 是一种独立的有别于数据存储的数据结构。尽管示例从数据库获取数据,但是数据来源是无所谓的;DataSet 总是呈现出一种统一的编程模型。这是一个简单的关于关系型数据库收集数据的示例。由于数据来源不可知,DataSe 阅读全文
posted @ 2013-11-18 16:39 安布雷拉 阅读(6381) 评论(1) 推荐(2) 编辑
摘要: 一些存储过程通过参数返回值。当参数在SQL表达式或者存储过程中被定义为“输出”,参数值会返回给调用者。返回值存储在 OleDbCommand 或者 SqlCommand 对象的参数集合的参数里。和下面的示例不同,即使 Connection 和 Command 都没有指定,你仍然可以建立参数,但是你必须创建参数集合和预期类型。 workParam = myCommand.Parameters.Add("@CustomerID", SQLDataType.NChar, 5); workParam.Value = "CUSTID";下面的示例演示了如何使用存储 阅读全文
posted @ 2013-11-18 16:31 安布雷拉 阅读(2716) 评论(0) 推荐(1) 编辑
摘要: Commands发出针对数据库的数据存储动作。例如,你可以执行一条命令插入或者删除数据。获取更多从数据库移动数据相关的信息,请参考“Update a Database from a DataSet”。Commands包含了对数据库发出的若干命令,而且在OleDbCommand情况下, 可以进行特定的数据存储. 例如,你可以执行存储过程调用的命令,又或许是一个“set quoted_identifier on”的命令。无论是何种命令,OleDbCommand还是SqlCommand可以被用于获取命令完成你的后端数据存储。使用传统的ADO,你可以通过Command对象,Connection对象,或 阅读全文
posted @ 2013-11-17 21:03 安布雷拉 阅读(3759) 评论(1) 推荐(1) 编辑
摘要: ADO.NET 概述ADO.NET是改进的ADO数据访问模型用于开发可扩展应用程序。他是专门为可伸缩性、无状态和XML核心的web而设计的。ADO.NET使用一些ADO对象,如Connection和Command对象,也引入了一些新对象。关键的新对象包括DataSet,DataReader,和DataAdapter。这种改进的ADO.NET和之前的数据架构的重要区别在于存在一个对象--DataSet对象--这是独立的不同于任何的数据存储。正因为如此,DataSet功能能够作为独立的实体。你可以将DataSet理解为总是断开连接对他包含的数据源和目标一无所知的记录集,在DataSet内部,就像一 阅读全文
posted @ 2013-11-17 15:44 安布雷拉 阅读(28585) 评论(1) 推荐(7) 编辑
摘要: Database Performance Tips for Developers对于开发人员的数据库性能技巧As a developer you may or may not need to go into the database and write queries or design tables and indexes, or help determine configuration of your SQL Server systems. But if you do, these tips should help to make that a more pain free process 阅读全文
posted @ 2013-09-04 10:39 安布雷拉 阅读(662) 评论(0) 推荐(0) 编辑
摘要: ORM TipsORM小窍门More and more people are using Object to Relational Mapping (ORM) tools to jump the divide between application code that is object oriented and a database that is storing information in a relational manner. These tools are excellent and radically improve development speed. But, there a 阅读全文
posted @ 2013-08-30 14:08 安布雷拉 阅读(429) 评论(0) 推荐(0) 编辑
摘要: (41)StringBuilder is NOT the answer for all string concatenation scenarios; String.Join could be招数41:StringBuilder不适用于所有字符串连接的场景;String.Join可能是Yes, if you are in a loop and adding to a string, then a StringBuilder *could* be most appropriate. However, the overhead of spinning up a StringBuilder inst 阅读全文
posted @ 2013-08-27 12:55 安布雷拉 阅读(386) 评论(0) 推荐(0) 编辑
摘要: (40)Take advantage of .NET 4.5 async constructs招数40:利用.NET 4.5异步结构With the arrival of .NET 4.5, writing async code correctly is easier than ever. Like any tool, it should be only applied where it makes most sense – in web use-cases this usually revolves around I/O operations (i.e. reading from disk, 阅读全文
posted @ 2013-08-22 15:12 安布雷拉 阅读(298) 评论(0) 推荐(0) 编辑
摘要: (39)Avoid using session state招数39:避免使用会话状态Where possible, you should try and avoid using session state. Whilst using one web server, performance is usually not a problem. This changes as soon as you need to scale to multiple servers, as different, and usually slower, techniques need to be used.如果可能, 阅读全文
posted @ 2013-08-20 17:27 安布雷拉 阅读(265) 评论(0) 推荐(0) 编辑
摘要: (32)Seven handy ViewState tips招数32:7条便利的ViewState技巧Every time I have to deal with a classic ASP.NET Web Forms application, one of the first things I look at is the resulting source, to check whether the DOM is a complete mess and whether the ViewState is an enormous, unnecessary blob of ugliness. Us 阅读全文
posted @ 2013-08-02 15:44 安布雷拉 阅读(344) 评论(0) 推荐(0) 编辑
摘要: (31)Know your loops招数31:认识你的循环for is the fastest way of iterating over a collection, foreach is a little slower, and LINQ queries are slowest.for是遍历集合最快的方法,foreach略慢一些,LINQ查询最慢。测试代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Diagn 阅读全文
posted @ 2013-08-01 14:13 安布雷拉 阅读(648) 评论(1) 推荐(0) 编辑
摘要: (30)Static collections招数30:静态集合If a collection is static, make sure it only contains the objects you need. If the collection is iterated over often, then the performance can be slow if you don’t remove unnecessary objects. Objects in a collection will be held in memory, even if they have been dispos 阅读全文
posted @ 2013-07-31 13:52 安布雷拉 阅读(297) 评论(0) 推荐(0) 编辑
摘要: (29)Before tackling any website performance issue, first verify the problem isn’t on the client招数29:在处理网站性能问题前,首先验证问题是否出在客户端Traditionally, many performance problems have been rooted in either the database or application server. 习惯上,许多性能问题要么根植于数据库或者应用服务器。However, with the proliferation of advanced Ja 阅读全文
posted @ 2013-07-29 14:16 安布雷拉 阅读(249) 评论(0) 推荐(0) 编辑
摘要: (28)Don’t assume that problems can only arise from business logic招数28:不要认为问题只会从业务层产生When beginning to diagnose performance problems, we often assume the problem is in our business logic. Don’t forget that the areas of our code that provide infrastructure can cause problems as well.当开始诊断性能问题时,我们一般认为问 阅读全文
posted @ 2013-07-26 14:29 安布雷拉 阅读(273) 评论(0) 推荐(0) 编辑
摘要: (27)Throw hardware at the problem, not developers招数27:把问题仍给硬件而不是开发人员As developers, we often want to fix problems with code, but don’t be afraid to ‘put the compiler down’ and throw some hardware at the problem.作为开发人员,我们通常想通过代码解决问题,但不要害怕‘批评编译器’和把问题仍给硬件。Performance problems caused by disk I/O bottlene 阅读全文
posted @ 2013-07-25 14:30 安布雷拉 阅读(295) 评论(0) 推荐(0) 编辑
摘要: (26)Don’t underestimate the value of the UI when tackling performance problems招数26:解决性能问题时不要低估UI的价值Simple UI tricks, such as progress bars, redirecting users’ attention using animation, or placing slower loading sections at the bottom of a page or offscreen, can often ‘fix’ a performance problem wit 阅读全文
posted @ 2013-07-24 14:17 安布雷拉 阅读(317) 评论(0) 推荐(0) 编辑
摘要: (25)Use the startMode attribute to reduce the load time for your ASP.NET site招数25:使用startMode属性来减少ASP.NET站点加载时间Every time you update your site, IIS must recompile it during the first request, so the initial request takes significantly longer than subsequent ones. An easy solution is to tell IIS to a 阅读全文
posted @ 2013-07-22 14:07 安布雷拉 阅读(444) 评论(0) 推荐(0) 编辑