Commit 2a2ff865 authored by Nick Craver's avatar Nick Craver

Fix Dapper.Contrib to prefer its attribute but still fall back to others

parent 0ec089b7
...@@ -290,15 +290,19 @@ private static string GetTableName(Type type) ...@@ -290,15 +290,19 @@ private static string GetTableName(Type type)
} }
else else
{ {
//NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework
var tableAttr = type
#if NETSTANDARD1_3 #if NETSTANDARD1_3
.GetTypeInfo() var info = type.GetTypeInfo();
#else
var info = type;
#endif #endif
.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic; //NOTE: This as dynamic trick falls back to handle both our own Table-attribute as well as the one in EntityFramework
if (tableAttr != null) var tableAttrName =
info.GetCustomAttribute<TableAttribute>(false)?.Name
?? (info.GetCustomAttributes(false).FirstOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic)?.Name;
if (tableAttrName != null)
{ {
name = tableAttr.Name; name = tableAttrName;
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment