Telerik OpenAccess ORM and the XML Metadata Source
来源:互联网 发布:windows7淘宝 编辑:程序博客网 时间:2024/06/05 00:43
原文地址:Telerik OpenAccess ORM and the XML Metadata Source
Telerik OpenAccess ORM and the XML Metadata Source
我们都知道Telerik OpenAccess ORM在2010年Q1版本发布的时候有了全新的面孔,所以这是发个博客谈谈这个新的可视化控件的一些特性和改进。今天我来谈谈新版的OpenAccess ORM最重大的改变之一,也就是XML – only映射。你们都知道之前这个产品所有的版本的映射信息是在混合定义在一些XML配置文件和CLR属性中的。通过很多客户的反馈和深思熟虑,我们决定使XML和属性分开独立作为你的模型元信息的源。你可以选择一个你自己喜欢。
我将从一个新的XML映射定义的简要概述开始。在以前的版本中,所有的XML映射信息分散在app.config和reversemapping.config文件中,现在它由可视化设计器生成并保存在[YourModelName].rlinq文件中。
当你用XML编辑器打开这个.rilnq文件的时候,可以看到很多信息。但是最后被OpenAccess运行时使用的模型映射信息是在节点里的。下面是一个类节点在新版中的例子:
<orm:table name="Categories" />
<orm:identity>
<orm:key-generator name="autoinc" />
<orm:single-field field-name="categoryID" />
</orm:identity>
<orm:field name="categoryID" property="CategoryID" null-value="none" type="System.Int32">
<orm:column name="CategoryID" sql-type="int" nullable="false" scale="0" primary-key="true" backend-calculated="true" ado-type="Int32" />
</orm:field>
<orm:field name="categoryName" property="CategoryName" null-value="none" type="System.String">
<orm:column name="CategoryName" sql-type="nvarchar" nullable="false" length="15" scale="0" ado-type="Varchar" />
</orm:field>
...
我们尽力使映射架构更直观-便于阅读和编辑。虽然可以手动修改设置,但是我强烈建议你通过可视化设计器来编辑。
你是怎么通过XML来定义元数据源的?
当你选择使用XML作为元数据源的时候(这是模型设置对话框的默认选项),OpenAccess执行一个MSBuild任务来提取映射信息并作为你的模型程序集的源嵌入其中
下面是通过XmlMetadataSource获取模型元数据的例子:
MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("EntityDiagrams1.rlinq"); NorthwindEntityDiagrams context = new NorthwindEntityDiagrams("MyConnection", null, metadataSource);
如果你在其他的程序集中执行这段代码-比如在一个引用你的模型程序集的网络应用,你还需要在程序集中指定.rlinq文件的位置。
Assembly modelAssembly = typeof(Customer).Assembly; MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource(modelAssembly,"EntityDiagrams1.rlinq");
XmlMetadataSource类是一个读取和发送一个模型元数据信息给OpenAccess运行时的类。它使你可以灵活的使用元数据源,用不同的初始化方法创建一个模型。比如你可以像例子一样从一个程序集的嵌入资源中获取模型,但是也可以从文件流中获取,或者是直接传入的XML字符串和硬盘某个地方一个XML文件。所以,你甚至根本不需要单独的.rlinq文件。
在此你可以使用这个API来调用由持久化类生成的新的OpenAccessContext类(你可以自己创建一个,也可以从OpenAccessContext基类派生一个类),也可以使用现有的IObjectScope API(对于给予IObjectScope的老项目特别有用)
下面是一个例子:
Assembly modelAssembly = typeof(Customer).Assembly; MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource(modelAssembly, EntityDiagrams1.rlinq"); MetadataContainer metadata = metadataSource.GetModel(); Database database = Database.Get("DbConnection", new BackendConfiguration(), metadata); IObjectScope scope = database.GetObjectScope();
总之,概括的说,XML元数据源只是你能用来表示OpenAccess映射元数据的一种方法,通过可视化设计器可以非常方便的使用。它是大多数不需要修改任何映射信息场景时的最佳选择。关于手动生成和操作映射,属性元数据源会是个好选择。这是我们稍后讨论的话题,敬请关注。
- Telerik OpenAccess ORM and the XML Metadata Source
- < telerik:GridEditCommandColumn/> and <telerik:GridButtonColumn> imagebutton hover
- Xml and the Nametable
- S60WebKit: Getting and Compiling the Source
- Tracing and Stepping through the Source Code
- The Source and Develop of RootKit
- Hackers and the Open Source Revolution
- Telerik Skinning for the RadControls
- ASM Metadata and Internals
- Exports and Metadata
- Which two are the uses of the ASM metadata backup and restore (AMBR) feature?
- Which two are the uses of the ASM metadata backup and restore (AMBR) feature? (Choose two.)
- Setting the -source and -target of the Java Compiler
- Telerik
- telerik
- telerik
- Cannot retrieve repository metadata (repomd.xml) for repository:Please verify its path and try again
- Identifying multiple/single values of metadata and recording into XML via .NET Client Object Model
- 摩托车继承自行车和机动车
- 毛细管网
- 宇宙中最大的神秘结构被发现 跨度达40亿光年
- NSString、Char* 、NSData之间的转换
- 拓展训练给企业注入了正能量
- Telerik OpenAccess ORM and the XML Metadata Source
- C++ 结构
- 由小见大——设计数据库表时应该注意的问题
- Uva11827 (GCD)
- JAVA "magic square"判定算法的实现。
- linux共享内存
- Spring中过滤敏感词
- 使用 Spring 进行单元测试
- 在控制台显示程序进度