Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Entity Developer 6.0 — New ORM Designer for Telerik Data Access

DZone's Guide to

Entity Developer 6.0 — New ORM Designer for Telerik Data Access

How to use the Entity Framework with Telerik's recently-deprecated visual designer and Visual Studio tools for their Data Access ORM data access framework.

· Big Data Zone
Free Resource

Access NoSQL and Big Data through SQL using standard drivers (ODBC, JDBC, ADO.NET). Free Download 

As Telerik announced a few months ago on their blog, they deprecated a visual designer and Visual Studio tools for their Data Access ORM (formerly, OpenAccess ORM) — a very popular and powerful data access framework. Since the Q2 2015 version, Data Access NuGet packages work only with code-only mapping. The deprecated Telerik Data Access Visual Designer was very popular among Telerik Data Access users, and there are a lot of user posts and comments with demands for a visual model designer for this ORM on different websites.

Seeing these requests, Devart decided to support Telerik Data Access in our ORM designer — Entity Developer. Entity Developer is a powerful ORM designer for several popular ORM solutions, and now we are glad to announce that it supports Telerik Data Access too!

Entity Developer provides full support for Fluent Data Access mapping — it supports all kinds of inheritances, structures, composite IDs, etc. Our Designer supports all the familiar visual designer features Telerik Data Access users are accustomed to and many more, and it can be used both as seamlessly integrated Visual Studio add-in and as a standalone application.

Easy to Start, Easy to Use

To start using our designer, just create a new Devart Data Access model via Create Model Wizard or open an existing .rlinq model that was created with the deprecated Visual Designer from Data Access' Visual Studio integration.

To create the Devart Data Access model for a Visual Studio project, right-click the project in the Solution Explorer and choose Add -> New Item from the shortcut menu. In the displayed dialogue, select "Devart Telerik Data Access Model". Then specify the model name in the Name box and click OK.

Note: In the standalone Entity Developer application, on the File menu click New Model… in order to open the wizard.

Create Model Wizard is displayed. Follow the wizard steps to create a database connection, select necessary tables, configure naming rules and other model settings, choose code generation templates and their options and automatically download and install the Telerik.DataAccess.Fluent NuGet package. In this wizard you can set the default parameters for the generated classes: default assembly and namespace, default schema, default identity generator, etc. You can also enable or disable automatic detection of many-to-many associations and TPT inheritances when creating the model.

Entity Developer allows you to generate mapping containing all the schema details or preserve only the cross-database schema information to create database-independent models. Alternatively you may disable storing the database schema information in the mapping.

After creating the model, Entity Developer can immediately generate class and mapping files for Telerik Data Access, and the generated code is ready-to-use in your project.

1-Create Model Wizard - Select Tables

Create Model Wizard - Model Settings

Create Model Wizard - Code Generation Templates

After creating the model, it is saved as an Entity Developer for Telerik Data Access model file with the .daml extension.

To create a Devart Data Access model from an existing .rlinq file that was created with Visual Designer from Data Access Visual Studio integration, just open the .rlinq file with Entity Developer and save the result model to a separate .daml file. The .rlinq file is not modified, it is only used as a source for an Entity Developer model. All the model entities, their relations and mapping are copied to the result Entity Developer model. After this you only need to add the new .daml model file to your project instead of the .rlinq file of the deprecated Telerik Visual Designer model.

Generated Code Example

Entity Developer generates the model context class, the Fluent mapping class, and POCO classes for model entities.

For example, here is the generated code of the model context class:

public partial class NorthwindDataAccessModel : OpenAccessContext
    {

        private static BackendConfiguration backend = GetBackendConfiguration();
        private static MetadataSource metadataSource = new NorthwindDataAccessModelMetadataSource();
        private static string connectionString = @"NorthwindDataAccessModelConnectionString";

        public NorthwindDataAccessModel() :
            base(connectionString, backend, metadataSource)
        {
            OnCreated();
        }

        public NorthwindDataAccessModel(BackendConfiguration backendConfiguration) :
            base(connectionString, backendConfiguration, metadataSource)
        {
          OnCreated();
        }

        public NorthwindDataAccessModel(string connection) :
            base(connection, backend, metadataSource)
        {
          OnCreated();
        }

        public NorthwindDataAccessModel(string connection, string cacheKey) :
            base(connection, cacheKey, backend, metadataSource)
        {
            OnCreated();
        }

        public NorthwindDataAccessModel(string connection, MetadataSource metadataSource) :
            base(connection, backend, metadataSource)
        {
          OnCreated();
        }

        public NorthwindDataAccessModel(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource) :
            base(connection, backendConfiguration, metadataSource)
        {
          OnCreated();
        }
        public NorthwindDataAccessModel(string connection, string cacheKey, BackendConfiguration backendConfiguration, MetadataSource metadataSource) :
            base(connection, cacheKey, backendConfiguration, metadataSource)
        {
          OnCreated();
        }

        public IQueryable Categories
        {
            get
            {
                return this.GetAll();
            }
        }

        public static BackendConfiguration GetBackendConfiguration()
        {
            BackendConfiguration backend = new BackendConfiguration();
            backend.Backend = "MsSql";
            backend.ProviderName = "System.Data.SqlClient";

            CustomizeBackendConfiguration(ref backend);
            return backend;
        }

        static partial void CustomizeBackendConfiguration(ref BackendConfiguration config);
        partial void OnCreated();
    }

Generated fluent mapping code:

    public partial class NorthwindDataAccessModelMetadataSource : FluentMetadataSource
    {
        protected override void SetContainerSettings(MetadataContainer container)
        {
            container.Name = "NorthwindDataAccessModel";
            container.DefaultNamespace = "WindowsFormsApplication1";
            container.DefaultMapping.NullForeignKey = true;
            OnSetContainerSettings(container);
        }
        protected override IList PrepareMapping()
        {
            List mappingConfigurations = new List();
            mappingConfigurations.Add(this.GetCategoryMappingConfiguration());

            OnPrepareMapping(mappingConfigurations);
            return mappingConfigurations;
        }

        #region Category Mapping

        public MappingConfiguration GetCategoryMappingConfiguration()
        {
            MappingConfiguration configuration = this.GetCategoryClassConfiguration();
            this.PrepareCategoryConfigurations(configuration);
            this.OnPrepareCategoryConfigurations(configuration);
            return configuration;
        }

        public MappingConfiguration GetCategoryClassConfiguration()
        {
            MappingConfiguration configuration = new MappingConfiguration();
            configuration.MapType(x => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("dbo.Categories");
            return configuration;
        }

        public void PrepareCategoryConfigurations(MappingConfiguration configuration)
        {
            configuration.HasProperty(x => x.CategoryID).ToColumn(@"CategoryID").IsIdentity(KeyGenerator.Autoinc).WithOpenAccessType(OpenAccessType.Int32).HasColumnType("int").IsNotNullable().HasPrecision(10);
            configuration.HasProperty(x => x.CategoryName).ToColumn(@"CategoryName").WithOpenAccessType(OpenAccessType.Varchar).HasColumnType("nvarchar").IsNotNullable().HasLength(15).IsUnicode();
            configuration.HasProperty(x => x.Description).ToColumn(@"Description").WithOpenAccessType(OpenAccessType.Varchar).HasColumnType("nvarchar").IsNullable().IsUnicode();
            configuration.HasProperty(x => x.Picture).ToColumn(@"Picture").WithOpenAccessType(OpenAccessType.VarBinary).HasColumnType("varbinary").IsNullable();
        }

        partial void OnPrepareCategoryConfigurations(MappingConfiguration configuration);

        #endregion

        #region Extensibility Method Definitions
        partial void OnSetContainerSettings(MetadataContainer container);
        partial void OnPrepareMapping(List mappingConfigurations);

        #endregion
    }

And here is a code, generated for the Category model class:

    public partial class Category {

        public Category()
        {
            OnCreated();
        }

        public virtual int CategoryID
        {
            get;
            set;
        }

        public virtual string CategoryName
        {
            get;
            set;
        }

        public virtual string Description
        {
            get;
            set;
        }

        public virtual byte[] Picture
        {
            get;
            set;
        }

        #region Extensibility Method Definitions

        partial void OnCreated();

        #endregion
    }

Design Approaches

With Entity Developer you can use Model-First and Database-First approaches to design your ORM model and generate code for it. It introduces new approaches for designing ORM models, boosts productivity, and facilitates the development of database applications. The Update From Database and Update To Database wizards detect all the database changes that can affect the model, e.g. created and deleted tables and views, their columns and foreign keys, column datatype changes, etc. All changes are displayed in an easy-to-understand form, and you can select only a part of the changes to apply. Entity Developer also includes Generate Database Wizard, which generates a DDL script, creating database tables.

Tweaking Configuration

Entity Developer for Data Access is also capable of generating Data Access configurations. You may tweak the Data Access configuration settings in the Model Settings dialogue box and then generate the configuration code either to the App.config file of the project or directly to the context class code. You can even disable configuration generation and create configurations yourself with the CustomizeBackendConfiguration(ref BackendConfiguration config) method.

Model Configuration

If a configuration is generated as context class code, it will look like the following:

        public static BackendConfiguration GetBackendConfiguration()
        {
            BackendConfiguration backend = new BackendConfiguration();
            backend.Backend = "MsSql";
            backend.ProviderName = "System.Data.SqlClient";
            backend.Runtime.AllowReadAfterDelete = true;
            backend.Runtime.AllowReadAfterDispose = true;
            backend.Runtime.ClassBehavior = DataAccessKind.ReadWrite;

            CustomizeBackendConfiguration(ref backend);
            return backend;
        }

And if it is generated to the config file, the following XML code is added to it:

  <configSections>
    <section name="openAccessConfiguration" type="Telerik.OpenAccess.Config.OpenAccessConfigSectionHandler, Telerik.OpenAccess" requirePermission="false" />
  </configSections>
  <openAccessConfiguration xmlns="http://www.telerik.com/OpenAcessConfiguration">
    <backendConfiguration name="NorthwindDataAccessModel" backend="msSql" providerName="System.Data.SqlClient">
      <runtime allowReadAfterDelete="true" allowReadAfterDispose="true" classBehavior="readWrite" />
    </backendConfiguration>
  </openAccessConfiguration>

Rich Mapping Functionality

Entity Developer for Data Access supports almost all features of the Data Access Fluent Mapping API. It supports mapping entity to several tables, one-to-many, one-to-one, and many-to-many associations, complex types, composite IDs, all kinds of inheritance hierarchies, enum types, etc.

It provides wide support for different kinds of stored procedures and functions, allowing you to create both methods with scalar results and returning datasets as complex types or entities from the stored routines.

Model Diagram

Queries and Data

When designing and especially when using the debugging model, it is often necessary to view table data or fill tables with some test data. Additionally, it’s very convenient to be able to check your model and mapping by querying data via the ORM. Entity Developer allows viewing and editing the data of tables, views, and model entities, creating and executing LINQ queries against the model, eliminating the need for additional applications, and reducing time for accessing these operations. You can see more details about working with queries and data in Entity Developer here.

Executing LINQ query against model

Productivity

Entity Developer provides powerful features to automate or speed-up common model editing operations. To accelerate the model design process, it provides wide support for drag-and-drop functionality. After you have established a database connection, you may drag database tables and views from the Database Explorer window to your model diagram to create classes for these tables with already defined mapping.

Advanced model refactoring features go even further and allow such operations as creating a TPC inheritance hierarchy from a group of classes or extracting common properties from several classes to a complex type to be performed almost instantly.

The fastest databases need the fastest drivers - learn how you can leverage CData Drivers for high performance NoSQL & Big Data Access.

Topics:
.net ,entity framework ,c# ,orm ,telerik data access ,visual studio

Published at DZone with permission of Jordan Sanders. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}