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
3 changes: 3 additions & 0 deletions Breeze.Client/Scripts/IBlade/a40_entityMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,9 @@ var CsdlMetadataParser = (function () {
}
}
if (dp) {
if (csdlProperty.displayName != undefined) {
dp.displayName = csdlProperty.displayName;
}
parentType.addProperty(dp);
addValidators(dp);
}
Expand Down
42 changes: 41 additions & 1 deletion Breeze.ContextProvider.EF6/EFContextProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public static String GetMetadataFromDbFirstAssembly(Assembly assembly, String re
// This is needed because the raw edmx has a different namespace than the CLR types that it references.
xDoc = UpdateCSpaceOSpaceMapping(xDoc, assembly, resourcePrefix);

AddUpdateDisplayNames(xDoc, assembly);
return XDocToJson(xDoc);
}

Expand Down Expand Up @@ -570,10 +571,47 @@ private static String GetMetadataFromDbContext(Object context) {
var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;
// This is needed because the raw edmx has a different namespace than the CLR types that it references.
xDoc = UpdateCSpaceOSpaceMapping(xDoc, objectContext);
AddUpdateDisplayNames(xDoc, dbContext.GetType().Assembly);
return XDocToJson(xDoc);
}

private static String GetMetadataFromObjectContext(Object context) {
private static void AddUpdateDisplayNames(XDocument xDoc, Assembly assembly)
{
XNamespace ns = "http://schemas.microsoft.com/ado/2009/11/edm";

XNamespace annotationNs = xDoc.Root.Attribute(XNamespace.Xmlns + "customannotation").Value;
foreach (var entityType in xDoc.Root.Elements(ns + "EntityType"))
{
//string className = entityType.Attribute("Name").Value;
//string typeName = string.Format("{0}.{1}, {2}", nameSpace, className, dbContext.GetType().Assembly.FullName);
//string typeName = string.Format("{0}.{1}", nameSpace, className);

//var ass = dbContext.GetType().Assembly;
//Type type = Type.GetType(nameSpace + "." + className, assemblyName => dbContext.GetType().Assembly, (assembly, tn, _) => ass.GetType(typeName));
var typeName = entityType.Attribute(annotationNs + "ClrType").Value;
typeName = typeName.Substring(0, typeName.IndexOf(','));
Type type = assembly.GetType(typeName);
foreach (var property in entityType.Elements(ns + "Property"))
{
var typeProperty = type.GetProperty(property.Attribute("Name").Value);
var displayAttribute = (DisplayAttribute)Attribute.GetCustomAttribute(typeProperty, typeof(DisplayAttribute));
if (displayAttribute != null && displayAttribute.Name != null)
{
property.SetAttributeValue("DisplayName", displayAttribute.Name);
}
else
{
var displayNameAttribute = (DisplayNameAttribute)Attribute.GetCustomAttribute(typeProperty, typeof(DisplayNameAttribute));
if (displayNameAttribute != null && displayNameAttribute.DisplayName != null)
{
property.SetAttributeValue("DisplayName", displayNameAttribute.DisplayName);
}
}
}
}
}

private static String GetMetadataFromObjectContext(Object context) {

var ocAssembly = context.GetType().Assembly;
var ocNamespace = context.GetType().Namespace;
Expand All @@ -584,6 +622,8 @@ private static String GetMetadataFromObjectContext(Object context) {

// This is needed because the raw edmx has a different namespace than the CLR types that it references.
xDoc = UpdateCSpaceOSpaceMapping(xDoc, objectContext);

AddUpdateDisplayNames(xDoc, context.GetType().Assembly);
return XDocToJson(xDoc);
}

Expand Down