In this case, instead of using a single regex parameter I would instead
suggest following the EntityInterfaces and MemberExposedAttributes
option by using comma-separated names.

In a truly ideal world we'd replace Parameters.cs/etc. with Mono.Options
or NDesk.Options [0], which would allow you to do "DbMetal -entity A
-entity B -entity C ...", using '-entity' for each type you wanted to
provide.

Thanks,
 - Jon

On Mon, 2009-10-26 at 15:36 +0100, Emanuele Aina wrote:
> In a ongoing effort to subvert DbMetal to our desires, I've also added a
> new option allow the selection of the entity types to be generated by
> means of a regular expression.
> 
> As usual, diff follows and gzipped patch attached.
> 
> We needed this and the /noDatacontext option to generate each entity in
> a different file when calling DbMetal from a script.
> 
> ---
>  .../CodeTextGenerator/CodeGenerator.Class.cs       |   10 +++++++++-
>  src/DbMetal/Parameters.cs                          |    9 +++++++++
>  2 files changed, 18 insertions(+), 1 deletions(-)
> 
> diff --git 
> a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
>  
> b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
> index dcea168..82792aa 100644
> --- 
> a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
> +++ 
> b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
> @@ -28,6 +28,7 @@ using System.Collections.Generic;
>  using System.Data.Linq.Mapping;
>  using System.Diagnostics;
>  using System.Linq;
> +using System.Text.RegularExpressions;
>  using DbLinq.Schema.Dbml;
>  using DbLinq.Schema.Dbml.Adapter;
>  using DbLinq.Util;
> @@ -48,7 +49,14 @@ namespace 
> DbMetal.Generator.Implementation.CodeTextGenerator
>      {
>          protected virtual void WriteClasses(CodeWriter writer, Database 
> schema, GenerationContext context)
>          {
> -            foreach (var table in schema.Tables)
> +            // filter entities to be generated, accept everything by default
> +            Regex filter = new Regex(".*", RegexOptions.Compiled);
> +            if (context.Parameters.EntityFilter != null) {
> +                // should match the whole type name
> +                filter = new Regex("^"+context.Parameters.EntityFilter+"$", 
> RegexOptions.Compiled);
> +            }
> +
> +            foreach (var table in schema.Tables.Where(t => 
> filter.IsMatch(t.Type.Name)))
>                  WriteClass(writer, table, schema, context);
>          }
>  
> diff --git a/src/DbMetal/Parameters.cs b/src/DbMetal/Parameters.cs
> index e38badc..170d795 100644
> --- a/src/DbMetal/Parameters.cs
> +++ b/src/DbMetal/Parameters.cs
> @@ -222,6 +222,15 @@ namespace DbMetal
>          public bool NoDataContext { get; set; }
>  
>          /// <summary>
> +        /// specifies which entities should be generated with a regex which
> +        /// should match the whole type name
> +        /// DbLinq specific
> +        /// </summary>
> +        [Option("Generate only entities that match the regex",
> +            ValueName = "regex", Group = 4)]
> +        public string EntityFilter { get; set; }
> +
> +        /// <summary>
>          /// specifies a provider (which here is a pair or ISchemaLoader and 
> IDbConnection implementors)
>          /// SQLMetal compatible
>          /// </summary>
> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to