TrackableEntities / trackable-entities

N-Tier Support for Entity Framework with WCF or ASP.NET Web API
http://trackableentities.github.io
MIT License
120 stars 36 forks source link

LoadRelatedEntities Helpers #219

Closed deetrim closed 5 years ago

deetrim commented 6 years ago

I had an issue with Foreign Keys which were based on GUID types.
The code below would not match the GUID type keys. I fixed the problem by adding a test for GUID . Not sure if that is a good thing or not but it solved my problem Please check if this should be fix in the code base Thanks

private static string GetQueryEntitySql(string entitySetName, string foreignKeyName, params object[] keyValues) { if (keyValues.Length == 0) return null; var ids = from k in keyValues // select k is string ? string.Format("'{0}'", k) : k.ToString(); -- replaced with statement below select k is string ? string.Format("'{0}'", k) : k is Guid ? string.Format("Guid '{0}'", k) : k.ToString();
string csvIds = string.Join(",", ids); string entitySql = string.Format ("SELECT VALUE x FROM {0} AS x WHERE x.{1} IN {{{2}}}", entitySetName, foreignKeyName, csvIds); return entitySql; }

tonysneed commented 5 years ago

Looks like you have a good workaround.