diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs index 8a50d39d..33ddf213 100644 --- a/src/GlobalSuppressions.cs +++ b/src/GlobalSuppressions.cs @@ -92,6 +92,7 @@ #region CA1811 Review uncalled private code [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Core.Submit.DataModificationItem.#ServerValues")] +[assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer.#InnerModelBuilder")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.QueryExecutor.#Inner")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Query.RestierQueryExecutor.#Inner")] [assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.ValidationResultDto.#Severity")] @@ -172,6 +173,7 @@ [assembly: SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "source", Scope = "member", Target = "Microsoft.Restier.Core.DataSourceStub.#GetPropertyValue`1(System.Object,System.String)")] [assembly: SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "propertyName", Scope = "member", Target = "Microsoft.Restier.Core.DataSourceStub.#GetPropertyValue`1(System.Object,System.String)")] [assembly: SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "odataProperties", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.RestierController`1.#GetQuery(System.Web.OData.Extensions.HttpRequestMessageProperties)")] +[assembly: SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer.#GetModelAsync(Microsoft.Restier.Core.Model.ModelContext,System.Threading.CancellationToken)")] #endregion #region CA2000 Dispose objects diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs index 3e59ff4d..93cbe34d 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/Model/ModelProducer.cs @@ -8,6 +8,7 @@ using System.Data.Entity.Core.Metadata.Edm; using System.Data.Entity.Infrastructure; #endif +using System.Globalization; using System.Linq; using System.Reflection; using System.Threading; @@ -62,27 +63,43 @@ public Task GetModelAsync(ModelContext context, CancellationToken can var dbContext = context.GetApiService(); var efModel = (dbContext as IObjectContextAdapter).ObjectContext.MetadataWorkspace; - // @robertmclaws: The query below actually returns all registered Containers across all registered DbContexts. - // It is likely a bug in some other part of OData. But we can roll with it. + + // @robertmclaws: The query below actually returns all registered Containers + // across all registered DbContexts. + // It is likely a bug in some other part of OData. But we can roll with it. var efEntityContainers = efModel.GetItems(DataSpace.CSpace); - // @robertmclaws: Because of the bug above, we should not make any assumptions about what is returned, and get - // the specific container we want to use. Even if the bug gets fixed, the next line should still - // continue to work. + + // @robertmclaws: Because of the bug above, we should not make any assumptions about what is returned, + // and get the specific container we want to use. Even if the bug gets fixed, the next line should still + // continue to work. var efEntityContainer = efEntityContainers.FirstOrDefault(c => c.Name == dbContext.GetType().Name); - // @robertmclaws: Now that we're doing a proper FirstOrDefault() instead of a Single(), we wont' crash if more - // than one is returned, and we can check for null and inform the user specifically what happened. + + // @robertmclaws: Now that we're doing a proper FirstOrDefault() instead of a Single(), + // we wont' crash if more than one is returned, and we can check for null + // and inform the user specifically what happened. if (efEntityContainer == null) { if (efEntityContainers.Count > 1) { // @robertmclaws: In this case, we have multiple DbContexts available, but none of them match up. // Tell the user what we have, and what we were expecting, so they can fix it. - var containerNames = efEntityContainers.Aggregate("", (current, next) => next.Name + ", "); - throw new Exception(string.Format(Resources.MultipleDbContextsExpectedException, containerNames.Substring(0, containerNames.Length - 2), efEntityContainer.Name)); + var containerNames = efEntityContainers.Aggregate( + string.Empty, (current, next) => next.Name + ", "); + throw new Exception(string.Format( + CultureInfo.InvariantCulture, + Resources.MultipleDbContextsExpectedException, + containerNames.Substring(0, containerNames.Length - 2), + efEntityContainer.Name)); } + // @robertmclaws: In this case, we only had one DbContext available, and if wasn't thw right one. - throw new Exception(string.Format(Resources.DbContextCouldNotBeFoundException, dbContext.GetType().Name, efEntityContainer.Name)); + throw new Exception(string.Format( + CultureInfo.InvariantCulture, + Resources.DbContextCouldNotBeFoundException, + dbContext.GetType().Name, + efEntityContainer.Name)); } + var itemCollection = (ObjectItemCollection)efModel.GetItemCollection(DataSpace.OSpace); foreach (var efEntitySet in efEntityContainer.EntitySets) diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.Designer.cs b/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.Designer.cs index 39fc17eb..498112db 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.Designer.cs +++ b/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -97,7 +97,7 @@ internal static string InvalidPointGeographyType { } /// - /// Looks up a localized string similar to This project has multiple EntityFrameworkApis using different DbContexts, and the correct context could not be loaded. \r\n The contexts available are '{0}' but the Container expects '{1}'.. + /// Looks up a localized string similar to This project has multiple EntityFrameworkApi using different DbContexts, and the correct context could not be loaded. \r\n The contexts available are '{0}' but the Container expects '{1}'.. /// internal static string MultipleDbContextsExpectedException { get { diff --git a/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.resx b/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.resx index e328fed3..ab975106 100644 --- a/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.resx +++ b/src/Microsoft.Restier.Providers.EntityFramework/Properties/Resources.resx @@ -130,7 +130,7 @@ Need 'Point type', while input is {0}. - This project has multiple EntityFrameworkApis using different DbContexts, and the correct context could not be loaded. \r\n The contexts available are '{0}' but the Container expects '{1}'. + This project has multiple EntityFrameworkApi using different DbContexts, and the correct context could not be loaded. \r\n The contexts available are '{0}' but the Container expects '{1}'. The precondition check for request {0} on resource {1} is failed. @@ -142,4 +142,4 @@ Unsupported type for property: {0}. - + \ No newline at end of file