CodeSmith's PLINQO: Replace & Extend LINQ to SQL
- Generate or update a LINQ to SQL dbml file from a database schema.
- Includes all tables, stored procedures, functions, and views with the ability to exclude objects based on regex patterns.
- Ability to automatically remove object prefix and suffixes (ie. tbl_ and usp_).
- Dbml file can still be customized with the normal Visual Studio 2008 designer.
- Dbml file can be refreshed based on the current database schema without losing customizations. (See Safe Attributes)
- Generation of the LINQ to SQL DataContext class.
- Generation of the LINQ to SQL entity classes.
- Generates one file per entity instead of one massive file.
- Generates partial classes where custom code can be written and won't be overwritten.
- Generated entity files are added to the project as code behind files to their corresponding custom entity files.
- Generation of entity manager classes.
- Adds customizable business rules engine to enforce entity validation, business and security rules.
- Provides access to common queries based on primary keys, foreign keys, and indexes.
- Common queries are exposed as IQueryable so they can be extended.
- All templates can be customized to meet your needs.
InfoQ recently had the opportunity to talk with Eric J. Smith, founder of CodeSmith Tools, LLC about PLINQO. Eric explained the motivation behind it:
Many developers, including ourselves, don't like black boxes. So our motivation in creating these templates was to remove that black box and to allow ourselves and other developers to be able to customize the output of the LINQ to SQL designers. We also wanted to extend the functionality of the generated classes to include business rules, authorization rules and other features.In the blog post announcing PLINQO as Professional LINQ to Objects, it states they are meant to replacement and extend the LINQ to SQL designers included in Visual Studio 2008. Since Microsoft has it's technology called LINQ to objects and LINQ to SQL, InfoQ asked if their templates are really a LINQ to SQL replacement or a LINQ to Objects replacement and why the the overlap in naming? Eric responded:
PLINQO is a replacement for LINQ to SQL and is not related to LINQ to Objects. We knew this was going to cause confusion, but we really wanted a fun name and we really liked the name PLINQO. PLINQO is a play on the Price is Right game, Plinko, which just happens to be the most fun game on Price is Right. :-)
On why a developer want to adopt your templates instead of simply keeping the ones provided by Microsoft:
The templates will work wit CodeSmith 4.0+ (see InfoQ coverage), and also within VS2008 with CodeSmith 4.1. In future releases, CodeSmith intends to add unit tests, UI generation and web services support. Paul Welter was the lead developer on the templates. Eric mentioned that the templates are in progress and any feedback would be appreciated. we would appreciate any feedback and ideas users have. Check out the CodePlex Project, and Quick Start.
There are several advantages to using the PLINQO templates over the designers. Here is a list of the main reasons:
- The designer black box and allow for customization of the ouput while still retaining the ability to use the .dbml designer to make customizations inside of Visual Studio.
- To easily generate your entire .dbml file for a database and then the ability to regenerate that .dbml file as the schema changes while preserving any customizations you may have made such as entity, property and relationship names. With the designer, if you make a database change, you need to drop the entity and re-add it to get any new columns or data type changes, which would cause you to lose any customizations you may have made. Also, using the templates allows you to exclude unwanted tables, stored procedures and views using filter expressions and automatically strip / clean entity and property names of things like prefixes and suffixes that your database schema may be using (ie. tbl_Customer to Customer).
- A business rules engine that allows you to enforce things like property length rules, required field rules, regex data validation rules as well as several other built in rules including authorization rules. The SubmitChanges method on the data context object will automatically run the rules against any entities in your change set. If all rules are not met, a BrokenRulesException will be thrown that contains a list of the broken rules.
- A manager class is generated for each entity that encapsulates all actions taken on an entity. Known common actions like retrieving entities by primary key, indexes, and foreign keys are generated. Any custom actions can be added and will be preserved during regeneration. While LINQ makes it easy to sprinkle your data access logic throughout your entire application, we still believe its poor design to do so and that is why we have included the manager classes.
PLINQO is a great example of this kinds of additions we can expect from CodeSmith and others to add value to Microsoft's LINQ technology. As is often the case, vendors see areas for improvement in a base technology and step up to make the developer's job that much easier. PLINQO is a very good first step to much more to come.
Sarah Howe Jul 06, 2015