> I'll rework my patches such that instead of separated
> --generate-datacontext and --entity options a single --type option will
> do, but it's not clear to me how it should also replace
> --entityInterfaces.

Here it is:

---
 .../CodeTextGenerator/CodeGenerator.Class.cs       |    8 +++++++-
 .../CodeTextGenerator/CodeGenerator.cs             |   13 ++++++++++---
 src/DbMetal/Parameters.cs                          |    8 ++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git 
a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs 
b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
index 2afdb7a..9daf975 100644
--- 
a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
+++ 
b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.Class.cs
@@ -48,7 +48,13 @@ namespace DbMetal.Generator.Implementation.CodeTextGenerator
     {
         protected virtual void WriteClasses(CodeWriter writer, Database 
schema, GenerationContext context)
         {
-            foreach (var table in schema.Tables)
+            IEnumerable<Table> tables = schema.Tables;
+
+            var types = context.Parameters.Types;
+            if (types.Count > 0)
+                tables = tables.Where(t => types.Contains(t.Type.Name));
+
+            foreach (var table in tables)
                 WriteClass(writer, table, schema, context);
         }
 
diff --git 
a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.cs 
b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.cs
index ed35680..3429406 100644
--- a/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.cs
+++ b/src/DbMetal/Generator/Implementation/CodeTextGenerator/CodeGenerator.cs
@@ -93,18 +93,25 @@ namespace DbMetal.Generator.Implementation.CodeTextGenerator
                 if (string.IsNullOrEmpty(entityNamespace))
                     entityNamespace = dbSchema.EntityNamespace;
 
+                bool generateDataContext = true;
+                var types = context.Parameters.Types;
+                if (types.Count > 0)
+                    generateDataContext = types.Contains(dbSchema.Class);
+
                 if (contextNamespace == entityNamespace)
                 {
                     using (WriteNamespace(codeWriter, contextNamespace))
                     {
-                        WriteDataContext(codeWriter, dbSchema, context);
+                        if (generateDataContext)
+                            WriteDataContext(codeWriter, dbSchema, context);
                         WriteClasses(codeWriter, dbSchema, context);
                     }
                 }
                 else
                 {
-                    using (WriteNamespace(codeWriter, contextNamespace))
-                        WriteDataContext(codeWriter, dbSchema, context);
+                    if (generateDataContext)
+                        using (WriteNamespace(codeWriter, contextNamespace))
+                            WriteDataContext(codeWriter, dbSchema, context);
                     using (WriteNamespace(codeWriter, entityNamespace))
                         WriteClasses(codeWriter, dbSchema, context);
                 }
diff --git a/src/DbMetal/Parameters.cs b/src/DbMetal/Parameters.cs
index a5ede79..a74ecfd 100644
--- a/src/DbMetal/Parameters.cs
+++ b/src/DbMetal/Parameters.cs
@@ -204,6 +204,8 @@ namespace DbMetal
         public string DatabaseConnectionProvider { get; set; }
 
         public string SqlDialectType { get; set; }
+
+        public IList<string> Types { get; set; }
 
         public bool GenerateTimestamps { get; set; }
 
@@ -225,6 +227,7 @@ namespace DbMetal
         {
             Schema = true;
             Culture = "en";
+            Types = new List<string>();
             GenerateTimestamps = true;
             EntityInterfaces = 
"INotifyPropertyChanging,INotifyPropertyChanged";//INotifyPropertyChanging 
INotifyPropertyChanged IModified
         }
@@ -306,6 +309,11 @@ namespace DbMetal
                 { "memberAttributes=",
                   "Comma separated {ATTRIBUTE(S)} of entity members in the 
generated code.",
                   attributes => MemberAttributes = attributes },
+                { "type=",
+                  "Generate only the {TYPE} selected, can be specified 
multiple times "
+                  +"and does not prevent references from being generated 
(default: "
+                  +"generate a DataContex subclass and all the entities in the 
schema).",
+                  type => Types.Add(type) },
                 { "generateEqualsAndHash",
                   "Generates overrides for Equals() and GetHashCode() 
methods.",
                   (bool v) => GenerateEqualsAndHash = v },
-- 


-- 
Emanuele Aina
Studio Associato Di Nunzio e Di Gregorio
http://dndg.it/
Via Maria Vittoria, 2
10123 Torino - Italy

--

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


Attachment: 0001-Add-the-type-option-to-DbMetal.patch.gz
Description: GNU Zip compressed data

Reply via email to