Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NMG.App/ConnectionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private string GetDefaultConnectionStringForServerType(ServerType serverType)
{
switch (serverType)
{
case ServerType.MSAccess:
return StringConstants.MSACCESS_CONN_STR_TEMPLATE;
case ServerType.Oracle:
return StringConstants.ORACLE_CONN_STR_TEMPLATE;
case ServerType.SqlServer:
Expand Down
33 changes: 17 additions & 16 deletions NMG.Core/ByCode/DBColumnMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NMG.Core.Domain;
using NMG.Core.TextFormatter;
using System.Text;
using NMG.Core.Util;

namespace NMG.Core.ByCode
{
Expand Down Expand Up @@ -32,15 +33,15 @@ public string IdSequenceMap(Column column, string sequenceName, ITextFormatter f
builder.AppendFormat("Id(x => x.{0}, map => ", formatter.FormatText(column.Name));
builder.AppendLine();
builder.AppendLine("\t\t\t\t{");
builder.AppendLine("\t\t\t\t\tmap.Column(\"" + column.Name + "\");");
builder.AppendLine("\t\t\t\t\tmap.Generator(Generators.Sequence, g => g.Params(new { sequence = \"" + sequenceName + "\" }));");
builder.AppendLine("\t\t\t\t\tmap.Column(" + column.Name.ToStringLiteral() + ");");
builder.AppendLine("\t\t\t\t\tmap.Generator(Generators.Sequence, g => g.Params(new { sequence = " + sequenceName.ToStringLiteral() + " }));");
builder.Append("\t\t\t\t});");
break;
case Language.VB:
builder.AppendFormat("Id(Function(x) x.{0}, Sub(map)", formatter.FormatText(column.Name));
builder.AppendLine();
builder.AppendLine("\t\t\t\t\tmap.Column(\"" + column.Name + "\")");
builder.AppendLine("\t\t\t\t\tmap.Generator(Generators.Sequence, Function(g) g.Params(New { sequence = \"" + sequenceName + "\" }))");
builder.AppendLine("\t\t\t\t\tmap.Column(" + column.Name.ToStringLiteral() + ")");
builder.AppendLine("\t\t\t\t\tmap.Generator(Generators.Sequence, Function(g) g.Params(New { sequence = " + sequenceName.ToStringLiteral() + " }))");
builder.Append("\t\t\t\tEnd Sub)");
break;
}
Expand All @@ -55,7 +56,7 @@ public string IdMap (Column column, ITextFormatter formatter)

if (column.Name.ToLower() != propertyName.ToLower())
{
mapList.Add("map.Column(\"" + column.Name + "\")");
mapList.Add("map.Column(" + column.Name.ToStringLiteral() + ")");
}
mapList.Add(column.IsIdentity ? "map.Generator(Generators.Identity)" : "map.Generator(Generators.Assigned)");

Expand All @@ -75,15 +76,15 @@ public string CompositeIdMap(IList<Column> columns, ITextFormatter formatter)
builder.AppendLine("\t\t\t\t{");
foreach (var column in columns)
{
builder.AppendLine("\t\t\t\t\tcompId.Property(x => x." + formatter.FormatText(column.Name) + ", m => m.Column(\"" + column.Name + "\"));");
builder.AppendLine("\t\t\t\t\tcompId.Property(x => x." + formatter.FormatText(column.Name) + ", m => m.Column(" + column.Name.ToStringLiteral() + "));");
}
builder.Append("\t\t\t\t});");
break;
case Language.VB:
builder.AppendLine("ComposedId(Sub(compId)");
foreach (var column in columns)
{
builder.AppendLine("\t\t\t\t\tcompId.Property(Function(x) x." + formatter.FormatText(column.Name) + ", Sub(m) m.Column(\"" + column.Name + "\"))");
builder.AppendLine("\t\t\t\t\tcompId.Property(Function(x) x." + formatter.FormatText(column.Name) + ", Sub(m) m.Column(" + column.Name.ToStringLiteral() + "))");
}
builder.AppendLine("\t\t\t\tEnd Sub)");
break;
Expand All @@ -108,7 +109,7 @@ public string Map(Column column, ITextFormatter formatter, bool includeLengthAnd
// Column
if (column.Name.ToLower() != propertyName.ToLower())
{
mapList.Add("map.Column(\"" + column.Name + "\")");
mapList.Add("map.Column(" + column.Name.ToStringLiteral() + ")");
}
// Not Null
if (!column.IsNullable)
Expand Down Expand Up @@ -200,16 +201,16 @@ public string Bag(HasMany hasMany, ITextFormatter formatter)
if (_language == Language.CSharp)
{
builder.AppendFormat(
"\t\t\tBag(x => x.{0}, colmap => {{ colmap.Key(x => x.Column(\"{1}\")); colmap.Inverse(true); }}, map => {{ map.OneToMany(); }});",
"\t\t\tBag(x => x.{0}, colmap => {{ colmap.Key(x => x.Column({1})); colmap.Inverse(true); }}, map => {{ map.OneToMany(); }});",
formatter.FormatPlural(hasMany.Reference),
hasMany.ReferenceColumn);
hasMany.ReferenceColumn.ToStringLiteral());
}
else if (_language == Language.VB)
{
builder.AppendFormat(
"\t\t\tBag(Function(x) x.{0}, Sub(colmap) colmap.Key(Function(x) x.Column(\"{1}\")), Sub(map) map.OneToMany())",
"\t\t\tBag(Function(x) x.{0}, Sub(colmap) colmap.Key(Function(x) x.Column({1})), Sub(map) map.OneToMany())",
formatter.FormatPlural(hasMany.Reference),
hasMany.ReferenceColumn);
hasMany.ReferenceColumn.ToStringLiteral());
}
return builder.ToString();
}
Expand All @@ -220,12 +221,12 @@ public string Reference(ForeignKey fk, ITextFormatter formatter)
if (fk.Columns.Count() == 1)
{
var mapList = new List<string>();
mapList.Add("map.Column(\"" + fk.Columns.First().Name + "\")");
mapList.Add("map.Column(" + fk.Columns.First().Name.ToStringLiteral() + ")");

// PropertyRef - Used with a FK that doesnt map to a primary key on referenced table.
if (!string.IsNullOrEmpty(fk.Columns.First().ForeignKeyColumnName))
{
mapList.Add("map.PropertyRef(\"" + formatter.FormatText(fk.Columns.First().ForeignKeyColumnName) + "\")");
mapList.Add("map.PropertyRef(" + formatter.FormatText(fk.Columns.First().ForeignKeyColumnName).ToStringLiteral() + ")");
}
if (!fk.Columns.First().IsNullable)
{
Expand All @@ -247,7 +248,7 @@ public string Reference(ForeignKey fk, ITextFormatter formatter)
var lastColumn = fk.Columns.Last();
foreach (var column in fk.Columns)
{
builder.AppendFormat("x => x.Name(\"{0}\")", column.Name);
builder.AppendFormat("x => x.Name({0})", column.Name.ToStringLiteral());

var isLastColumn = lastColumn == column;
if (!isLastColumn)
Expand All @@ -267,7 +268,7 @@ public string Reference(ForeignKey fk, ITextFormatter formatter)
var lastColumn = fk.Columns.Last();
foreach (var column in fk.Columns)
{
builder.AppendFormat("x.Name(\"{0}\")", column.Name);
builder.AppendFormat("x.Name({0})", column.Name.ToStringLiteral());

var isLastColumn = lastColumn == column;
if (!isLastColumn)
Expand Down
6 changes: 6 additions & 0 deletions NMG.Core/DataTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public Type MapFromDBType(ServerType serverType, string dataType, int? dataLengt
return MapFromOracleDBType(dataType, dataLength, dataPrecision, dataScale);
case ServerType.MySQL:
return MapFromMySqlDBType(dataType, dataLength, dataPrecision, dataScale);
case ServerType.MSAccess:
return MapFromMSAccessDbType(dataType, dataLength, dataPrecision, dataScale);
case ServerType.SQLite:
return MapFromSqliteDbType(dataType, dataLength, dataPrecision, dataScale);
case ServerType.PostgreSQL:
Expand Down Expand Up @@ -167,6 +169,10 @@ private Type MapFromSqliteDbType(string dataType, int? dataLength, int? dataPrec
{
return MapFromDBType(dataType, dataLength, dataPrecision, dataScale);
}
private Type MapFromMSAccessDbType(string dataType, int? dataLength, int? dataPrecision, int? dataScale)
{
return MapFromDBType(dataType, dataLength, dataPrecision, dataScale);
}

private Type MapFromInformixDbType(string dataType, int? dataLength, int? dataPrecision, int? dataScale)
{
Expand Down
3 changes: 2 additions & 1 deletion NMG.Core/Domain/ServerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ServerType
Sybase,
Informix,
Ingres,
CUBRID
CUBRID,
MSAccess
}
}
3 changes: 2 additions & 1 deletion NMG.Core/Fluent/DBColumnMapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text;
using NMG.Core.Domain;
using NMG.Core.TextFormatter;
using NMG.Core.Util;

namespace NMG.Core.Fluent
{
Expand All @@ -10,7 +11,7 @@ public string Map(Column column, string fieldName, ITextFormatter Formatter, boo
{
var mappedStrBuilder = new StringBuilder(string.Format("Map(x => x.{0})", fieldName));
mappedStrBuilder.Append(Constants.Dot);
mappedStrBuilder.Append("Column(\"" + column.Name + "\")");
mappedStrBuilder.Append("Column(" + column.Name.ToStringLiteral() + ")");

if (!column.IsNullable)
{
Expand Down
5 changes: 3 additions & 2 deletions NMG.Core/Generator/ByCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NMG.Core.Domain;
using NMG.Core.ByCode;
using NMG.Core.TextFormatter;
using NMG.Core.Util;

namespace NMG.Core.Generator
{
Expand Down Expand Up @@ -61,12 +62,12 @@ public CodeCompileUnit GetCompleteCompileUnit(string mapName)
// Table Name - Only ouput if table is different than the class name.
if (Table.Name.ToLower() != className.ToLower())
{
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Table(\"" + Table.Name + "\");"));
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Table(" + Table.Name.ToStringLiteral() + ");"));
}
// Scheme / Owner Name
if (!string.IsNullOrEmpty(Table.Owner))
{
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Schema(\"" + Table.Owner + "\");"));
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Schema(" + Table.Owner.ToStringLiteral() + ");"));
}

constructor.Statements.Add(new CodeSnippetStatement(TABS + string.Format("Lazy({0});", appPrefs.UseLazy ? "true" : "false")));
Expand Down
11 changes: 6 additions & 5 deletions NMG.Core/Generator/EntityFrameworkGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NMG.Core.Domain;
using NMG.Core.Fluent;
using NMG.Core.TextFormatter;
using NMG.Core.Util;

namespace NMG.Core.Generator
{
Expand Down Expand Up @@ -53,14 +54,14 @@ public CodeCompileUnit GetCompleteCompileUnit(string className)
newType.BaseTypes.Add(string.Format("EntityTypeConfiguration<{0}{1}>", appPrefs.ClassNamePrefix, pascalCaseTextFormatter.FormatSingular(Table.Name)));

var constructor = new CodeConstructor {Attributes = MemberAttributes.Public};
constructor.Statements.Add(new CodeSnippetStatement(TABS + "ToTable(\"" + Table.Name + "\");"));
constructor.Statements.Add(new CodeSnippetStatement(TABS + "ToTable(" + Table.Name.ToStringLiteral() + ");"));
if (appPrefs.UseLazy)
constructor.Statements.Add(new CodeSnippetStatement(TABS + "LazyLoad();"));

if (UsesSequence)
{
var fieldName = FixPropertyWithSameClassName(Table.PrimaryKey.Columns[0].Name, Table.Name);
constructor.Statements.Add(new CodeSnippetStatement(String.Format(TABS + "Id(x => x.{0}).Column(x => x.{1}).GeneratedBy.Sequence(\"{2}\")", Formatter.FormatText(fieldName), fieldName, appPrefs.Sequence)));
constructor.Statements.Add(new CodeSnippetStatement(String.Format(TABS + "Id(x => x.{0}).Column(x => x.{1}).GeneratedBy.Sequence({2})", Formatter.FormatText(fieldName), fieldName, appPrefs.Sequence.ToStringLiteral())));
}
else if (Table.PrimaryKey != null && Table.PrimaryKey.Type == PrimaryKeyType.PrimaryKey)
{
Expand Down Expand Up @@ -127,7 +128,7 @@ private static CodeSnippetStatement GetIdMapCodeSnippetStatement(ApplicationPref
var fieldName = FixPropertyWithSameClassName(propertyName, table.Name);
var pkAlsoFkQty = (from fk in table.ForeignKeys.Where(fk => fk.UniquePropertyName == pkColumnName) select fk).Count();
if (pkAlsoFkQty > 0) fieldName = fieldName + "Id";
return new CodeSnippetStatement(string.Format(TABS + "Id(x => x.{0}).{1}.Column(\"{2}\");", formatter.FormatText(fieldName), idGeneratorType, pkColumnName));
return new CodeSnippetStatement(string.Format(TABS + "Id(x => x.{0}).{1}.Column({2});", formatter.FormatText(fieldName), idGeneratorType, pkColumnName.ToStringLiteral()));
}

private static CodeSnippetStatement GetIdMapCodeSnippetStatement(PrimaryKey primaryKey, Table table, ITextFormatter formatter)
Expand All @@ -140,7 +141,7 @@ private static CodeSnippetStatement GetIdMapCodeSnippetStatement(PrimaryKey prim
var fieldName = FixPropertyWithSameClassName(propertyName, table.Name);
var pkAlsoFkQty = (from fk in table.ForeignKeys.Where(fk => fk.UniquePropertyName == pkColumn.Name) select fk).Count();
if (pkAlsoFkQty > 0) fieldName = fieldName + "Id";
var tmp = String.Format(".KeyProperty(x => x.{0}, \"{1}\")", fieldName, pkColumn.Name);
var tmp = String.Format(".KeyProperty(x => x.{0}, {1})", fieldName, pkColumn.Name.ToStringLiteral());
keyPropertyBuilder.Append(first ? tmp : "\n" + TABS + " " + tmp);
first = false;
}
Expand All @@ -164,7 +165,7 @@ public EFOneToMany(ITextFormatter formatter, PascalCaseTextFormatter pascalCaseT
public CodeSnippetStatement Create(HasMany hasMany)
{
var hasManySnippet = string.Format("HasMany(x => x.{0}).WithMany(x => x.{1})", Formatter.FormatPlural(hasMany.Reference), pascalCaseTextFormatter.FormatSingular(hasMany.PKTableName));
var keySnippet = string.Format(".Map(m => {{m.ToTable(\"{0}\"); m.MapLeftKey(\"{1}\"); m.MapRightKey(\"{2}\");}})", hasMany.Reference, hasMany.ReferenceColumn, hasMany.ReferenceColumn);
var keySnippet = string.Format(".Map(m => {{m.ToTable({0}); m.MapLeftKey({1}); m.MapRightKey({2});}})", hasMany.Reference.ToStringLiteral(), hasMany.ReferenceColumn.ToStringLiteral(), hasMany.ReferenceColumn.ToStringLiteral());
return new CodeSnippetStatement(string.Format(AbstractGenerator.TABS + "{0}{1};", hasManySnippet, keySnippet));
}
}
Expand Down
21 changes: 11 additions & 10 deletions NMG.Core/Generator/FluentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NMG.Core.Domain;
using NMG.Core.Fluent;
using NMG.Core.TextFormatter;
using NMG.Core.Util;

namespace NMG.Core.Generator
{
Expand Down Expand Up @@ -53,15 +54,15 @@ public CodeCompileUnit GetCompleteCompileUnit(string className)
newType.BaseTypes.Add(string.Format("ClassMap<{0}{1}>", appPrefs.ClassNamePrefix, pascalCaseTextFormatter.FormatSingular(Table.Name)));

var constructor = new CodeConstructor {Attributes = MemberAttributes.Public};
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Table(\"" + Table.Name + "\");"));
constructor.Statements.Add(new CodeSnippetStatement(TABS + "Table(" + Table.Name.ToStringLiteral() + ");"));
if (appPrefs.UseLazy)
constructor.Statements.Add(new CodeSnippetStatement(TABS + "LazyLoad();"));

if(UsesSequence)
{
var fieldName = FixPropertyWithSameClassName(Table.PrimaryKey.Columns[0].Name, Table.Name);
constructor.Statements.Add(new CodeSnippetStatement(String.Format(TABS + "Id(x => x.{0}).Column(x => x.{1}).GeneratedBy.Sequence(\"{2}\")",
Formatter.FormatText(fieldName), fieldName, appPrefs.Sequence)));
constructor.Statements.Add(new CodeSnippetStatement(String.Format(TABS + "Id(x => x.{0}).Column(x => x.{1}).GeneratedBy.Sequence({2})",
Formatter.FormatText(fieldName), fieldName, appPrefs.Sequence.ToStringLiteral())));
}
else if (Table.PrimaryKey !=null && Table.PrimaryKey.Type == PrimaryKeyType.PrimaryKey)
{
Expand All @@ -83,11 +84,11 @@ public CodeCompileUnit GetCompleteCompileUnit(string className)
var pkAlsoFkQty = (from fks in Table.ForeignKeys.Where(fks => fks.UniquePropertyName == name) select fks).Count();
if (pkAlsoFkQty > 1)
{
constructor.Statements.Add(new CodeSnippetStatement(string.Format(TABS + "References(x => x.{0}).Column(\"{1}\").ForeignKey(\"{2}\");", fieldName, fk.Columns.First().Name, fk.Columns.First().ConstraintName)));
constructor.Statements.Add(new CodeSnippetStatement(string.Format(TABS + "References(x => x.{0}).Column({1}).ForeignKey({2});", fieldName, fk.Columns.First().Name.ToStringLiteral(), fk.Columns.First().ConstraintName.ToStringLiteral())));
}
else
{
constructor.Statements.Add(new CodeSnippetStatement(string.Format(TABS + "References(x => x.{0}).Column(\"{1}\");", fieldName, fk.Columns.First().Name)));
constructor.Statements.Add(new CodeSnippetStatement(string.Format(TABS + "References(x => x.{0}).Column({1});", fieldName, fk.Columns.First().Name.ToStringLiteral())));
}

}
Expand Down Expand Up @@ -135,10 +136,10 @@ private static CodeSnippetStatement GetIdMapCodeSnippetStatement(ApplicationPref
fieldName = fieldName + "Id";
}

return new CodeSnippetStatement(string.Format(TABS + "Id(x => x.{0}).{1}.Column(\"{2}\");",
return new CodeSnippetStatement(string.Format(TABS + "Id(x => x.{0}).{1}.Column({2});",
formatter.FormatText(fieldName),
idGeneratorType,
pkColumnName));
pkColumnName.ToStringLiteral()));
}

private static CodeSnippetStatement GetIdMapCodeSnippetStatement(PrimaryKey primaryKey, Table table, ITextFormatter formatter)
Expand All @@ -155,7 +156,7 @@ private static CodeSnippetStatement GetIdMapCodeSnippetStatement(PrimaryKey prim
fieldName = fieldName + "Id";
}

var tmp = String.Format(".KeyProperty(x => x.{0}, \"{1}\")",fieldName, pkColumn.Name);
var tmp = String.Format(".KeyProperty(x => x.{0}, {1})",fieldName, pkColumn.Name.ToStringLiteral());
keyPropertyBuilder.Append(first ? tmp : "\n" + TABS + " " + tmp);
first = false;
}
Expand Down Expand Up @@ -189,8 +190,8 @@ public CodeSnippetStatement Create(HasMany hasMany)
{
var hasManySnippet = string.Format("HasMany(x => x.{0})", Formatter.FormatPlural(hasMany.Reference));
var keySnippet = hasMany.AllReferenceColumns.Count == 1 ?
string.Format(".KeyColumn(\"{0}\")", hasMany.ReferenceColumn) :
string.Format(".KeyColumns({0})", hasMany.AllReferenceColumns.Aggregate("new string[] { ", (a, b) => a + "\"" + b + "\", ", c => c.Substring(0, c.Length - 2) + " }"));
string.Format(".KeyColumn({0})", hasMany.ReferenceColumn.ToStringLiteral()) :
string.Format(".KeyColumns({0})", hasMany.AllReferenceColumns.Aggregate("new string[] { ", (a, b) => a + b.ToStringLiteral() + ", ", c => c.Substring(0, c.Length - 2) + " }"));

return new CodeSnippetStatement(string.Format(AbstractGenerator.TABS + "{0}{1};", hasManySnippet, keySnippet));
}
Expand Down
Loading