diff --git a/RESTier.sln b/RESTier.sln index 2c6037d7..fd8eea36 100644 --- a/RESTier.sln +++ b/RESTier.sln @@ -13,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Web", "Web", "{9D3D8728-C31 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.Core", "src\Microsoft.Restier.Core\Microsoft.Restier.Core.csproj", "{300B769A-3513-49D0-A035-7DB965C8D2A4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.AspNetCore", "src\Microsoft.Restier.AspNetCore\Microsoft.Restier.AspNetCore.csproj", "{97E94F97-E73B-4074-8587-AE1B91B4D61E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.AspNet", "src\Microsoft.Restier.AspNet\Microsoft.Restier.AspNet.csproj", "{8ECF4E97-1816-44AD-AD63-6ACF287ED520}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.EntityFramework", "src\Microsoft.Restier.EntityFramework\Microsoft.Restier.EntityFramework.csproj", "{0E373B2A-2ED2-4566-A275-6BE81CFFE00B}" @@ -25,8 +23,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.Tests.Ent EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.Tests.AspNet", "src\Microsoft.Restier.Tests.AspNet\Microsoft.Restier.Tests.AspNet.csproj", "{FD305A0A-5680-4C38-9917-84233F35DE3F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Restier.Tests.AspNetCore", "src\Microsoft.Restier.Tests.AspNetCore\Microsoft.Restier.Tests.AspNetCore.csproj", "{39D4AC9D-091B-437E-A616-3E9D77804BDB}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{901E6A2A-23EC-4BC8-B4C6-A3EF70D72702}" ProjectSection(SolutionItems) = preProject src\Directory.Build.props = src\Directory.Build.props @@ -52,10 +48,6 @@ Global {300B769A-3513-49D0-A035-7DB965C8D2A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {300B769A-3513-49D0-A035-7DB965C8D2A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {300B769A-3513-49D0-A035-7DB965C8D2A4}.Release|Any CPU.Build.0 = Release|Any CPU - {97E94F97-E73B-4074-8587-AE1B91B4D61E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97E94F97-E73B-4074-8587-AE1B91B4D61E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97E94F97-E73B-4074-8587-AE1B91B4D61E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97E94F97-E73B-4074-8587-AE1B91B4D61E}.Release|Any CPU.Build.0 = Release|Any CPU {8ECF4E97-1816-44AD-AD63-6ACF287ED520}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8ECF4E97-1816-44AD-AD63-6ACF287ED520}.Debug|Any CPU.Build.0 = Debug|Any CPU {8ECF4E97-1816-44AD-AD63-6ACF287ED520}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -76,10 +68,6 @@ Global {FD305A0A-5680-4C38-9917-84233F35DE3F}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD305A0A-5680-4C38-9917-84233F35DE3F}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD305A0A-5680-4C38-9917-84233F35DE3F}.Release|Any CPU.Build.0 = Release|Any CPU - {39D4AC9D-091B-437E-A616-3E9D77804BDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {39D4AC9D-091B-437E-A616-3E9D77804BDB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {39D4AC9D-091B-437E-A616-3E9D77804BDB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {39D4AC9D-091B-437E-A616-3E9D77804BDB}.Release|Any CPU.Build.0 = Release|Any CPU {3EAB0AED-2BE2-4120-B26E-3401B86C4DC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3EAB0AED-2BE2-4120-B26E-3401B86C4DC2}.Release|Any CPU.ActiveCfg = Release|Any CPU {3EAB0AED-2BE2-4120-B26E-3401B86C4DC2}.Release|Any CPU.Build.0 = Release|Any CPU @@ -96,13 +84,11 @@ Global {37B52FD3-E72B-406F-8C5A-F146256D7743} = {76B4E51F-233E-4DD3-AABF-A6F47788040D} {9D3D8728-C31B-4D5E-B471-79A9DBBA0E58} = {76B4E51F-233E-4DD3-AABF-A6F47788040D} {300B769A-3513-49D0-A035-7DB965C8D2A4} = {D8A3183C-1E9C-4D6C-AC72-4EF938EC9895} - {97E94F97-E73B-4074-8587-AE1B91B4D61E} = {9D3D8728-C31B-4D5E-B471-79A9DBBA0E58} {8ECF4E97-1816-44AD-AD63-6ACF287ED520} = {9D3D8728-C31B-4D5E-B471-79A9DBBA0E58} {0E373B2A-2ED2-4566-A275-6BE81CFFE00B} = {37B52FD3-E72B-406F-8C5A-F146256D7743} {16DBAD48-C935-4BF1-BC4A-925031AEA0FA} = {724F25F3-B47A-4A80-8F7A-08B2E8121D10} {EB7010EC-4AD2-4CEB-8757-46447FEC80C7} = {724F25F3-B47A-4A80-8F7A-08B2E8121D10} {FD305A0A-5680-4C38-9917-84233F35DE3F} = {724F25F3-B47A-4A80-8F7A-08B2E8121D10} - {39D4AC9D-091B-437E-A616-3E9D77804BDB} = {724F25F3-B47A-4A80-8F7A-08B2E8121D10} {3EAB0AED-2BE2-4120-B26E-3401B86C4DC2} = {DB42E0B8-C0C7-4DE4-9437-2B2A229B5F8F} {B75D79EE-D5C0-4E1B-82CB-9505880A2730} = {724F25F3-B47A-4A80-8F7A-08B2E8121D10} EndGlobalSection diff --git a/src/Microsoft.Restier.AspNetCore/Microsoft.Restier.AspNetCore.csproj b/src/Microsoft.Restier.AspNetCore/Microsoft.Restier.AspNetCore.csproj deleted file mode 100644 index 0f5c35e7..00000000 --- a/src/Microsoft.Restier.AspNetCore/Microsoft.Restier.AspNetCore.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netcoreapp2.2 - - - - - - - diff --git a/src/Microsoft.Restier.EntityFrameworkCore/App.config b/src/Microsoft.Restier.EntityFrameworkCore/App.config deleted file mode 100644 index 8aa83c95..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/App.config +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Microsoft.Restier.EntityFrameworkCore/Microsoft.Restier.Providers.EntityFramework7.csproj_old b/src/Microsoft.Restier.EntityFrameworkCore/Microsoft.Restier.Providers.EntityFramework7.csproj_old deleted file mode 100644 index 28cd6c78..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/Microsoft.Restier.Providers.EntityFramework7.csproj_old +++ /dev/null @@ -1,192 +0,0 @@ - - - - - {D54A765E-4604-4C73-868B-0E0459B3A6B6} - Library - Properties - Microsoft.Restier.Providers.EntityFramework - Microsoft.Restier.Providers.EntityFramework7 - $(OutputPath)$(AssemblyName).xml - $(CodeAnalysis) - ..\Strict.ruleset - v4.5.1 - - - - false - - - true - TRACE;DEBUG;CODE_ANALYSIS;EF7 - - - true - - - - - ..\..\packages\Microsoft.EntityFrameworkCore.1.1.2\lib\net451\Microsoft.EntityFrameworkCore.dll - - - ..\..\packages\Microsoft.EntityFrameworkCore.Relational.1.1.2\lib\net451\Microsoft.EntityFrameworkCore.Relational.dll - - - ..\..\packages\Microsoft.Extensions.Caching.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.Caching.Abstractions.dll - - - ..\..\packages\Microsoft.Extensions.Caching.Memory.1.1.1\lib\net451\Microsoft.Extensions.Caching.Memory.dll - - - ..\..\packages\Microsoft.Extensions.DependencyInjection.1.1.0\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll - - - ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - - ..\..\packages\Microsoft.Extensions.Logging.1.1.1\lib\netstandard1.1\Microsoft.Extensions.Logging.dll - - - ..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.1\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll - - - ..\..\packages\Microsoft.Extensions.Options.1.1.1\lib\netstandard1.0\Microsoft.Extensions.Options.dll - - - ..\..\packages\Microsoft.Extensions.Primitives.1.1.0\lib\netstandard1.0\Microsoft.Extensions.Primitives.dll - - - ..\..\packages\Microsoft.OData.Edm.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll - - - ..\..\packages\Remotion.Linq.2.1.1\lib\net45\Remotion.Linq.dll - True - - - - ..\..\packages\System.Collections.Immutable.1.3.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - - - - - - ..\..\packages\System.Diagnostics.DiagnosticSource.4.3.1\lib\portable-net45+win8+wpa81\System.Diagnostics.DiagnosticSource.dll - - - ..\..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll - True - - - - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.3.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - - - - - - Properties\CommonAssemblyInfo.cs - - - GlobalSuppressions.cs - true - - - EntityFrameworkApi.cs - - - Model.Shared\ModelMapper.cs - - - Model.Shared\ModelProducer.cs - - - Query.Shared\QueryExecutor.cs - - - Query.Shared\QueryExpressionProcessor.cs - - - Query.Shared\QueryExpressionSourcer.cs - - - ServiceCollectionExtensions.cs - - - Submit.Shared\SubmitExecutor.cs - - - Shared\Ensure.cs - - - Shared\ExpressionHelperMethods.cs - - - Shared\ExpressionHelpers.cs - - - Shared\EnumerableExtensions.cs - - - Shared\TypeExtensions.cs - - - SharedResources.EntityFramework.Designer.cs - True - True - SharedResources.resx - - - - True - True - Resources.resx - - - - - - {f1beab8d-82d4-4bbb-a5c6-ba0e6872e508} - Microsoft.Restier.Core - - - - - Designer - - - Designer - - - - - CodeAnalysisDictionary.xml - - - - - - - - - - - ResXFileCodeGenerator - SharedResources.EntityFramework.Designer.cs - Microsoft.Restier.Shared - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - \ No newline at end of file diff --git a/src/Microsoft.Restier.EntityFrameworkCore/Properties/AssemblyInfo.cs b/src/Microsoft.Restier.EntityFrameworkCore/Properties/AssemblyInfo.cs deleted file mode 100644 index 8077ef53..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RESTier Entity Framework 7 Module")] -[assembly: AssemblyDescription("A module that connects the RESTier to an Entity Framework based data source proxy.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("Microsoft.Restier.Providers.EntityFramework")] -[assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5880279B-620A-4745-88D0-58685A9B93E4")] \ No newline at end of file diff --git a/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.Designer.cs b/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.Designer.cs deleted file mode 100644 index 9cf96699..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.Designer.cs +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Microsoft.Restier.Providers.EntityFramework.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Restier.Providers.EntityFramework.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to A DataModificationEntry must be either New, Update or Delete.. - /// - internal static string DataModificationMustBeCUD { - get { - return ResourceManager.GetString("DataModificationMustBeCUD", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Could not find the specified resource.. - /// - internal static string ResourceNotFound { - get { - return ResourceManager.GetString("ResourceNotFound", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unsupported type for property: {0}.. - /// - internal static string UnsupportedPropertyType { - get { - return ResourceManager.GetString("UnsupportedPropertyType", resourceCulture); - } - } - } -} diff --git a/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.resx b/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.resx deleted file mode 100644 index 103f5e27..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/Properties/Resources.resx +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - A DataModificationEntry must be either New, Update or Delete. - - - Could not find the specified resource. - The target entity not found for modification - - - Unsupported type for property: {0}. - - \ No newline at end of file diff --git a/src/Microsoft.Restier.EntityFrameworkCore/Submit/ChangeSetInitializer.cs b/src/Microsoft.Restier.EntityFrameworkCore/Submit/ChangeSetInitializer.cs deleted file mode 100644 index 54ee91e6..00000000 --- a/src/Microsoft.Restier.EntityFrameworkCore/Submit/ChangeSetInitializer.cs +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.OData.Edm; -using Microsoft.Restier.Core; -using Microsoft.Restier.Core.Query; -using Microsoft.Restier.Core.Submit; -using Microsoft.Restier.Providers.EntityFramework.Properties; - -namespace Microsoft.Restier.Providers.EntityFramework -{ - /// - /// To prepare changed entries for the given . - /// For this class we cannot reuse EF6 ChangeSetPreparer code, since many types used here have their type name or - /// member name changed. - /// - public class ChangeSetInitializer : IChangeSetInitializer - { - private static MethodInfo prepareEntryGeneric = typeof(ChangeSetInitializer) - .GetMethod("PrepareEntry", BindingFlags.Instance | BindingFlags.NonPublic); - - /// - /// Asynchronously prepare the . - /// - /// The submit context class used for preparation. - /// The cancellation token. - /// The task object that represents this asynchronous operation. - public async Task InitializeAsync( - SubmitContext context, - CancellationToken cancellationToken) - { - DbContext dbContext = context.GetApiService(); - - foreach (var entry in context.ChangeSet.Entries.OfType()) - { - object strongTypedDbSet = dbContext.GetType().GetProperty(entry.ResourceSetName).GetValue(dbContext); - Type entityType = strongTypedDbSet.GetType().GetGenericArguments()[0]; - - // This means request resource is sub type of resource type - if (entry.ActualResourceType != null && entityType != entry.ActualResourceType) - { - entityType = entry.ActualResourceType; - } - - MethodInfo prepareEntryMethod = prepareEntryGeneric.MakeGenericMethod(entityType); - - var task = (Task)prepareEntryMethod.Invoke( - obj: this, - parameters: new[] { context, dbContext, entry, strongTypedDbSet, cancellationToken }); - await task; - } - } - - /// - /// Convert a Edm type value to Resource Framework supported value type - /// - /// The type of the property defined in CLR class - /// The value from OData deserializer and in type of Edm - /// The converted value object - public virtual object ConvertToEfValue(Type type, object value) - { - // string[EdmType = Enum] => System.Enum - if (TypeHelper.IsEnum(type)) - { - return Enum.Parse(TypeHelper.GetUnderlyingTypeOrSelf(type), (string)value); - } - - // Edm.Date => System.DateTime[SqlType = Date] - if (value is Date) - { - var dateValue = (Date)value; - return (DateTime)dateValue; - } - - // System.DateTimeOffset => System.DateTime[SqlType = DateTime or DateTime2] - if (value is DateTimeOffset && TypeHelper.IsDateTime(type)) - { - var dateTimeOffsetValue = (DateTimeOffset)value; - return dateTimeOffsetValue.DateTime; - } - - // Edm.TimeOfDay => System.TimeSpan[SqlType = Time] - if (value is TimeOfDay && TypeHelper.IsTimeSpan(type)) - { - var timeOfDayValue = (TimeOfDay)value; - return (TimeSpan)timeOfDayValue; - } - - // In case key is long type, when put an resource, key value will be from key parsing which is type of int - if (value is int && type == typeof(long)) - { - return Convert.ToInt64(value, CultureInfo.InvariantCulture); - } - - return value; - } - - private static async Task FindResource( - SubmitContext context, - DataModificationItem item, - CancellationToken cancellationToken) - { - var apiBase = context.GetApiService(); - IQueryable query = apiBase.GetQueryableSource(item.ResourceSetName); - query = item.ApplyTo(query); - - QueryResult result = await apiBase.QueryAsync(new QueryRequest(query), cancellationToken); - - object resource = result.Results.SingleOrDefault(); - if (resource == null) - { - throw new ResourceNotFoundException(Resources.ResourceNotFound); - } - - // This means no If-Match or If-None-Match header - if (item.OriginalValues == null || item.OriginalValues.Count == 0) - { - return resource; - } - - resource = item.ValidateEtag(result.Results.AsQueryable()); - return resource; - } - - private async Task PrepareEntry( - SubmitContext context, - DbContext dbContext, - DataModificationItem entry, - DbSet set, - CancellationToken cancellationToken) where TEntity : class - { - Type entityType = typeof(TEntity); - TEntity entity; - - if (entry.DataModificationItemAction == DataModificationItemAction.Insert) - { - // TODO: See if Create method is in DbSet<> in future EF7 releases, as the one EF6 has. - entity = (TEntity)Activator.CreateInstance(typeof(TEntity)); - - SetValues(entity, entityType, entry.LocalValues); - set.Add(entity); - } - else if (entry.DataModificationItemAction == DataModificationItemAction.Remove) - { - entity = (TEntity)await ChangeSetInitializer.FindResource(context, entry, cancellationToken); - set.Remove(entity); - } - else if (entry.DataModificationItemAction == DataModificationItemAction.Update) - { - if (entry.IsFullReplaceUpdateRequest) - { - entity = (TEntity)CreateFullUpdateInstance(entry, entityType); - dbContext.Update(entity); - } - else - { - entity = (TEntity)await ChangeSetInitializer.FindResource(context, entry, cancellationToken); - - var dbEntry = dbContext.Attach(entity); - SetValues(dbEntry, entry); - } - } - else - { - throw new NotSupportedException(Resources.DataModificationMustBeCUD); - } - - entry.Resource = entity; - } - - private object CreateFullUpdateInstance(DataModificationItem entry, Type entityType) - { - // The algorithm for a "FullReplaceUpdate" is taken from ObjectContextServiceProvider.ResetResource - // in WCF DS, and works as follows: - // - Create a new, blank instance of the entity. - // - Copy over the key values and set any updated values from the client on the new instance. - // - Then apply all the properties of the new instance to the instance to be updated. - // This will set any unspecified properties to their default value. - object newInstance = Activator.CreateInstance(entityType); - - SetValues(newInstance, entityType, entry.ResourceKey); - SetValues(newInstance, entityType, entry.LocalValues); - - return newInstance; - } - - private void SetValues(EntityEntry dbEntry, DataModificationItem entry) - { - foreach (KeyValuePair propertyPair in entry.LocalValues) - { - PropertyEntry propertyEntry = dbEntry.Property(propertyPair.Key); - object value = propertyPair.Value; - if (value == null) - { - // If the property value is null, we set null in the entry too. - propertyEntry.CurrentValue = null; - continue; - } - - Type type = TypeHelper.GetUnderlyingTypeOrSelf(propertyEntry.Metadata.ClrType); - value = ConvertToEfValue(type, value); - if (value != null && !type.IsInstanceOfType(value)) - { - var dic = value as IReadOnlyDictionary; - if (dic == null) - { - throw new NotSupportedException(string.Format( - CultureInfo.InvariantCulture, - Resources.UnsupportedPropertyType, - propertyPair.Key)); - } - - value = Activator.CreateInstance(type); - SetValues(value, type, dic); - } - - propertyEntry.CurrentValue = value; - } - } - - private void SetValues(object instance, Type instanceType, IReadOnlyDictionary values) - { - foreach (KeyValuePair propertyPair in values) - { - object value = propertyPair.Value; - PropertyInfo propertyInfo = instanceType.GetProperty(propertyPair.Key); - if (value == null) - { - // If the property value is null, we set null in the object too. - propertyInfo.SetValue(instance, null); - continue; - } - - Type type = TypeHelper.GetUnderlyingTypeOrSelf(propertyInfo.PropertyType); - value = ConvertToEfValue(type, value); - if (value != null && !type.IsInstanceOfType(value)) - { - var dic = value as IReadOnlyDictionary; - if (dic == null) - { - throw new NotSupportedException(string.Format( - CultureInfo.InvariantCulture, - Resources.UnsupportedPropertyType, - propertyPair.Key)); - } - - value = Activator.CreateInstance(type); - SetValues(value, type, dic); - } - - propertyInfo.SetValue(instance, value); - } - } - } -} diff --git a/src/Microsoft.Restier.Tests.AspNetCore/Microsoft.Restier.Tests.AspNetCore.csproj b/src/Microsoft.Restier.Tests.AspNetCore/Microsoft.Restier.Tests.AspNetCore.csproj deleted file mode 100644 index 318b2f58..00000000 --- a/src/Microsoft.Restier.Tests.AspNetCore/Microsoft.Restier.Tests.AspNetCore.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - netcoreapp2.2 - - false - - - - - - - - - - - - -