Skip to content

Commit

Permalink
.net 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Voronov committed Nov 13, 2020
1 parent a4cb2a0 commit addf0b4
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 60 deletions.
10 changes: 0 additions & 10 deletions NuGet.config

This file was deleted.

16 changes: 8 additions & 8 deletions dependencies.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project>
<PropertyGroup>
<ComponentModelAnnotations>4.7.0</ComponentModelAnnotations>
<CoreFxVersion>4.7.2</CoreFxVersion>
<ComponentModelAnnotations>5.0.0</ComponentModelAnnotations>
<CoreFxVersion>5.0.0</CoreFxVersion>
<CSharpVersion>8.0</CSharpVersion>
<EfCoreVersion>5.0.0-*</EfCoreVersion>
<EfCoreVersion>5.0.0</EfCoreVersion>
<FrameworkVersion>net48</FrameworkVersion>
<JsonNetVersion>12.0.3</JsonNetVersion>
<NetStandardVersion>net5.0</NetStandardVersion>
<NetCoreAppVersion>net5.0</NetCoreAppVersion>
<NetCoreVersion>3.1.8</NetCoreVersion>
<NetCoreVersion>5.0.0</NetCoreVersion>
<NpgsqlVersion>5.0.0-*</NpgsqlVersion>
<ODataLibVersion>7.7.2</ODataLibVersion>
<OdataToEntityVersion>2.5.0</OdataToEntityVersion>
<SystemInteractiveAsyncVersion>4.1.1</SystemInteractiveAsyncVersion>
<TestSdkVersion>16.7.1</TestSdkVersion>
<ODataLibVersion>7.7.3</ODataLibVersion>
<OdataToEntityVersion>2.6.0</OdataToEntityVersion>
<SystemInteractiveAsyncVersion>5.0.0</SystemInteractiveAsyncVersion>
<TestSdkVersion>16.8.0</TestSdkVersion>
<Version>$(OdataToEntityVersion)</Version>
<XunitVersion>2.4.1</XunitVersion>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion source/OdataToEntity.AspNetCore/OeDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Security.Permissions;
using System.Threading.Tasks;

namespace OdataToEntity.AspNetCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using OdataToEntity.EfCore.DynamicDataContext.Types;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
Expand Down Expand Up @@ -133,13 +132,13 @@ private void CreateNavigationProperties(Microsoft.EntityFrameworkCore.ModelBuild
}
}
}
private static Func<DynamicType, bool> GetDefaultValueFunc(IPropertyBase propertyBase)
private static Delegate GetDefaultValueFunc(IProperty property)
{
ParameterExpression parameterExpression = Expression.Parameter(typeof(DynamicType));
Expression expression = PropertyBase.CreateMemberAccess(propertyBase, parameterExpression, propertyBase.PropertyInfo);
expression = Expression.Convert(expression, propertyBase.ClrType);
expression = expression.MakeHasDefaultValue(propertyBase);
return Expression.Lambda<Func<DynamicType, bool>>(expression, new[] { parameterExpression }).Compile();
ParameterExpression parameterExpression = Expression.Parameter(property.DeclaringEntityType.ClrType);
Expression expression = PropertyBase.CreateMemberAccess(property, parameterExpression, property.PropertyInfo);
expression = Expression.Convert(expression, property.ClrType);
expression = expression.MakeHasDefaultValue(property);
return Expression.Lambda(expression, new[] { parameterExpression }).Compile();
}

public DynamicMetadataProvider MetadataProvider { get; }
Expand Down
36 changes: 16 additions & 20 deletions source/OdataToEntity.EfCore/OeEfCoreDataAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,17 @@ public override void AddEntity(Object dataContext, ODataResourceBase entry)
{
var context = (DbContext)dataContext;
EntityEntry<TEntity> entityEntry = context.Add(CreateEntity(context, entry));
InternalEntityEntry internalEntry = entityEntry.GetInfrastructure();
AddInstanceAnnotation(entry, internalEntry);
AddInstanceAnnotation(entry, entityEntry);

IReadOnlyList<IProperty> keyProperties = _entityType.FindPrimaryKey().Properties;
for (int i = 0; i < keyProperties.Count; i++)
if (keyProperties[i].ValueGenerated == ValueGenerated.OnAdd)
{
Object value = internalEntry.GetCurrentValue(keyProperties[i]);
internalEntry.SetTemporaryValue(keyProperties[i], value, false);
}
entityEntry.Property(keyProperties[i].Name).IsTemporary = true;
}
private static void AddInstanceAnnotation(ODataResourceBase entry, InternalEntityEntry internalEntityEntry)
private static void AddInstanceAnnotation(ODataResourceBase entry, EntityEntry entityEntry)
{
entry.InstanceAnnotations.Add(new ODataInstanceAnnotation("ef.InternalEntityEntryValue",
new Infrastructure.OeOdataValue<InternalEntityEntry>(internalEntityEntry)));
var odataValue = new Infrastructure.OeOdataValue<EntityEntry>(entityEntry);
entry.InstanceAnnotations.Add(new ODataInstanceAnnotation("ef.EntityEntryValue", odataValue));
}
public override void AttachEntity(Object dataContext, ODataResourceBase entry)
{
Expand All @@ -105,15 +101,15 @@ public override void AttachEntity(Object dataContext, ODataResourceBase entry)
if (internalEntry == null)
{
TEntity entity = CreateEntity(context, entry);
internalEntry = context.Attach(entity).GetInfrastructure();
AddInstanceAnnotation(entry, internalEntry);
EntityEntry entityEntry = context.Attach(entity);
AddInstanceAnnotation(entry, entityEntry);

IKey key = _entityType.FindPrimaryKey();
IReadOnlyList<IProperty> keyProperties = _entityType.FindPrimaryKey().Properties;
foreach (ODataProperty odataProperty in entry.Properties)
{
IProperty property = _entityType.FindProperty(odataProperty.Name);
if (!key.Properties.Contains(property))
internalEntry.SetPropertyModified(property);
if (!keyProperties.Contains(property))
entityEntry.Property(property.Name).IsModified = true;
}
}
else
Expand Down Expand Up @@ -168,11 +164,11 @@ private InternalEntityEntry GetEntityEntry(T context, ODataResourceBase entity)
}
private Object[] GetKeyValues(ODataResourceBase entity)
{
IKey key = _entityType.FindPrimaryKey();
var keyValues = new Object[key.Properties.Count];
IReadOnlyList<IProperty> keyProperties = _entityType.FindPrimaryKey().Properties;
var keyValues = new Object[keyProperties.Count];
for (int i = 0; i < keyValues.Length; i++)
{
String keyName = key.Properties[i].Name;
String keyName = keyProperties[i].Name;
foreach (ODataProperty odataProperty in entity.Properties)
if (String.Compare(odataProperty.Name, keyName, StringComparison.OrdinalIgnoreCase) == 0)
{
Expand Down Expand Up @@ -232,12 +228,12 @@ public override void RemoveEntity(Object dataContext, ODataResourceBase entry)
public override void UpdateEntityAfterSave(Object dataContext, ODataResourceBase resource)
{
foreach (ODataInstanceAnnotation instanceAnnotation in resource.InstanceAnnotations)
if (instanceAnnotation.Value is Infrastructure.OeOdataValue<InternalEntityEntry> internalEntry)
if (instanceAnnotation.Value is Infrastructure.OeOdataValue<EntityEntry> entityEntry)
{
PropertyValues propertyValues = internalEntry.Value.ToEntityEntry().CurrentValues;
PropertyValues propertyValues = entityEntry.Value.CurrentValues;
foreach (ODataProperty odataProperty in resource.Properties)
{
IProperty property = internalEntry.Value.EntityType.FindProperty(odataProperty.Name);
IProperty property = entityEntry.Value.Property(odataProperty.Name).Metadata;
if (property.ValueGenerated != ValueGenerated.Never || property.IsForeignKey())
odataProperty.Value = OeEdmClrHelper.CreateODataValue(propertyValues[property]);
}
Expand Down
2 changes: 1 addition & 1 deletion source/OdataToEntity.GraphQL/OdataToEntity.GraphQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="3.0.0.*" />
<PackageReference Include="GraphQL" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion source/OdataToEntity.GraphQL/OeGraphTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,21 @@ private QueryArgument[] CreateQueryArguments(Type entityType, bool onlyStructura
{
if (fieldType.Type == null)
{
String name;
IGraphType resolvedType = fieldType.ResolvedType;
if (resolvedType is NonNullGraphType nonNullGraphType)
{
resolvedType = nonNullGraphType.ResolvedType;
name = resolvedType.Name;
}
else if (resolvedType is ListGraphType listGraphType)
name = listGraphType.ResolvedType.Name;
else
name = resolvedType.Name;

Type inputObjectGraphType = typeof(InputObjectGraphType<>).MakeGenericType(resolvedType.GetType());
var inputObjectGraph = (IInputObjectGraphType)Activator.CreateInstance(inputObjectGraphType)!;
queryArgument = new QueryArgument(inputObjectGraphType) { Name = resolvedType.Name, ResolvedType = inputObjectGraph };
queryArgument = new QueryArgument(inputObjectGraphType) { Name = name, ResolvedType = inputObjectGraph };
}
else
{
Expand Down
1 change: 0 additions & 1 deletion source/OdataToEntity/Parsers/OePropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public readonly struct OePropertyAccessor
{
private readonly int _hashCode;
private readonly MemberInfo[] _propertyInfos;
public static readonly PropertyExpressionKey Comparer = new PropertyExpressionKey();

private PropertyExpressionKey(MemberInfo[] memberInfos, int hashCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="3.0.0.*" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="3.0.0.*" />
<PackageReference Include="GraphQL" Version="3.1.3" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EfCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EfCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="3.1.4" />
<PackageReference Include="linq2db.SqlServer" Version="3.1.4" />
<PackageReference Include="linq2db" Version="3.1.6" />
<PackageReference Include="linq2db.SqlServer" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EfCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EfCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="3.1.4" />
<PackageReference Include="linq2db" Version="3.1.6" />
<PackageReference Include="System.ComponentModel.Annotations" Version="$(ComponentModelAnnotations)" />
</ItemGroup>

Expand Down
6 changes: 2 additions & 4 deletions test/OdataToEntity.Test/OrderContextOptions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OData.Edm;
using System;
using System.Collections.Concurrent;
using OdataToEntity.EfCore;

namespace OdataToEntity.Test.Model
{
Expand All @@ -19,15 +17,15 @@ public static IEdmModel BuildDbEdmModel(IEdmModel _, bool __)
{
return DbFixtureInitDb.CreateEdmModel();
}
public static DbContextOptions Create(String databaseName)
public static DbContextOptions<OrderContext> Create(String databaseName)
{
return Create<OrderContext>(databaseName);
}
public static DbContextOptions Create(bool _)
{
throw new NotSupportedException();
}
public static DbContextOptions Create<T>(String databaseName) where T : DbContext
public static DbContextOptions<T> Create<T>(String databaseName) where T : DbContext
{
var optionsBuilder = new DbContextOptionsBuilder<T>();
optionsBuilder.UseSqlite(GetConnection(databaseName));
Expand Down
5 changes: 3 additions & 2 deletions test/OdataToEntity.Test/OrderDataAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq.Expressions;
using Microsoft.OData.Edm;
using System.Linq.Expressions;

namespace OdataToEntity.Test.Model
{
Expand All @@ -9,7 +10,7 @@ public OrderDataAdapter() :
{
}

protected override Expression TranslateExpression(Expression expression)
protected override Expression TranslateExpression(IEdmModel edmModel, Expression expression)
{
return new SQLiteVisitor().Visit(expression);
}
Expand Down

0 comments on commit addf0b4

Please sign in to comment.