ColumnAlias support.
This commit is contained in:
Родитель
719e33a8a1
Коммит
0412adeba4
|
@ -8,9 +8,11 @@
|
|||
#>
|
||||
<#+
|
||||
Action BeforeGenerateLinqToDBModel = () => {};
|
||||
Action AfterGenerateLinqToDBModel = () => {};
|
||||
Action AfterGenerateLinqToDBModel = () => {};
|
||||
|
||||
bool GenerateObsoleteAttributeFoAliases;
|
||||
bool GenerateObsoleteAttributeForAliases;
|
||||
bool IsCompactColumns = true;
|
||||
bool IsCompactColumnAliases = true;
|
||||
|
||||
void GenerateTypesFromMetadata()
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ void GenerateTypesFromMetadata()
|
|||
new[] { t.DataContextPropertyName },
|
||||
null);
|
||||
|
||||
if (GenerateObsoleteAttributeFoAliases)
|
||||
if (GenerateObsoleteAttributeForAliases)
|
||||
aProp.Attributes.Add(new Attribute("Obsolete", "\"Use " + t.DataContextPropertyName + " instead.\""));
|
||||
|
||||
aliases.Members.Add(aProp);
|
||||
|
@ -94,9 +96,10 @@ void GenerateTypesFromMetadata()
|
|||
aProp.Comment.AddRange(comments);
|
||||
}
|
||||
|
||||
var columns = new MemberGroup { IsCompact = true };
|
||||
var nPKs = t.Columns.Values.Count(c => c.IsPrimaryKey);
|
||||
var allNullable = t.Columns.Values.All (c => c.IsNullable || c.IsIdentity);
|
||||
var columns = new MemberGroup { IsCompact = IsCompactColumns };
|
||||
var columnAliases = new MemberGroup { IsCompact = IsCompactColumnAliases, Region = "Alias members" };
|
||||
var nPKs = t.Columns.Values.Count(c => c.IsPrimaryKey);
|
||||
var allNullable = t.Columns.Values.All (c => c.IsNullable || c.IsIdentity);
|
||||
|
||||
foreach (var c in t.Columns.Values)
|
||||
{
|
||||
|
@ -163,14 +166,19 @@ void GenerateTypesFromMetadata()
|
|||
else if (!c.IsIdentity)
|
||||
c.Attributes.Add(new Attribute("NotNull"));
|
||||
|
||||
var columnComments = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(c.Description))
|
||||
{
|
||||
c.Comment.Add("/ <summary>");
|
||||
columnComments.Add("/ <summary>");
|
||||
foreach (var line in c.Description.Split('\n'))
|
||||
c.Comment.Add("/ " + line.TrimEnd());
|
||||
c.Comment.Add("/ </summary>");
|
||||
columnComments.Add("/ " + line.TrimEnd());
|
||||
columnComments.Add("/ </summary>");
|
||||
}
|
||||
|
||||
if (columnComments.Count > 0)
|
||||
c.Comment.AddRange(columnComments);
|
||||
|
||||
// End line comment.
|
||||
//
|
||||
c.EndLineComment = c.ColumnType;
|
||||
|
@ -179,10 +187,33 @@ void GenerateTypesFromMetadata()
|
|||
SetPropertyValue(c, "IsEditable", true);
|
||||
|
||||
columns.Members.Add(c);
|
||||
|
||||
// Alias.
|
||||
//
|
||||
if (c.AliasName != null && c.AliasName != c.MemberName)
|
||||
{
|
||||
var caProp = new Property(
|
||||
c.Type,
|
||||
c.AliasName,
|
||||
new[] { c.MemberName },
|
||||
new[] { c.MemberName + " = value;"});
|
||||
|
||||
caProp.Comment.AddRange(columnComments);
|
||||
|
||||
if (GenerateObsoleteAttributeForAliases)
|
||||
caProp.Attributes.Add(new Attribute("Obsolete", "\"Use " + c.MemberName + " instead.\""));
|
||||
|
||||
caProp.Attributes.Add(new Attribute("ColumnAlias", "\"" + c.MemberName + "\""));
|
||||
|
||||
columnAliases.Members.Add(caProp);
|
||||
}
|
||||
}
|
||||
|
||||
t.Members.Add(columns);
|
||||
|
||||
if (columnAliases.Members.Count > 0)
|
||||
t.Members.Add(columnAliases);
|
||||
|
||||
if (GenerateAssociations)
|
||||
{
|
||||
var keys = t.ForeignKeys.Values.ToList();
|
||||
|
@ -235,7 +266,7 @@ void GenerateTypesFromMetadata()
|
|||
if (comments.Count > 0)
|
||||
aClass.Comment.AddRange(comments);
|
||||
|
||||
if (GenerateObsoleteAttributeFoAliases)
|
||||
if (GenerateObsoleteAttributeForAliases)
|
||||
aClass.Attributes.Add(new Attribute("Obsolete", "\"Use " + t.TypeName + " instead.\""));
|
||||
|
||||
Model.Types.Add(aClass);
|
||||
|
|
Загрузка…
Ссылка в новой задаче