Skip to content

Commit

Permalink
add support odat.nextLink
Browse files Browse the repository at this point in the history
  • Loading branch information
voronov-maxim committed Nov 5, 2017
1 parent 74bf166 commit 7593c93
Show file tree
Hide file tree
Showing 43 changed files with 391 additions and 449 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ var dataAdapter = new OeEf6DataAdapter<OrderEf6Context>();
EdmModel edmModel = dataAdapter.BuildEdmModelFromEf6Model();
```


### Sample OData query
For use odata.nextLink, the next link of a collection with partial results set property PageSize class OeParser
```c#
//Create adapter data access, where OrderContext your DbContext
var dataAdapter = new OeEfCoreDataAdapter<Model.OrderContext>();
//Create query parser
var parser = new OeParser(new Uri("http://dummy"), dataAdapter, dataAdapter.BuildEdmModel());
var parser = new OeParser(new Uri("http://dummy"), dataAdapter, dataAdapter.BuildEdmModel()) { PageSize = 2 };
//Query
var uri = new Uri("http://dummy/Orders?$select=Name");
//The result of the query
Expand Down
5 changes: 3 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<EfCoreVersion>2.0.0</EfCoreVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<NetStandardVersion>2.0.0</NetStandardVersion>
<ODataLib>7.3.1</ODataLib>
<ODataLibVersion>7.3.1</ODataLibVersion>
<OdataToEntityVersion>1.3.0</OdataToEntityVersion>
<SystemInteractiveAsyncVersion>3.1.1</SystemInteractiveAsyncVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<XunitVersion>2.3.0</XunitVersion>
<XunitVersion>2.3.1</XunitVersion>
</PropertyGroup>
</Project>
17 changes: 13 additions & 4 deletions sln/OdataToEntity.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
VisualStudioVersion = 15.0.27004.2006
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OdataToEntity", "..\source\OdataToEntity\OdataToEntity.csproj", "{70ED8CE4-4FA6-418A-A5BC-8697F5CA0B03}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OdataToEntity", "..\source\OdataToEntity\OdataToEntity.csproj", "{70ED8CE4-4FA6-418A-A5BC-8697F5CA0B03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OdataToEntity.Ef6", "..\source\OdataToEntity.Ef6\OdataToEntity.Ef6.csproj", "{BC8C07B9-92B0-46F6-A6BB-A9D8B3B78C91}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OdataToEntity.Ef6", "..\source\OdataToEntity.Ef6\OdataToEntity.Ef6.csproj", "{BC8C07B9-92B0-46F6-A6BB-A9D8B3B78C91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OdataToEntity.EfCore", "..\source\OdataToEntity.EfCore\OdataToEntity.EfCore.csproj", "{94E8BF46-2821-4890-9E07-D1FA5C797C92}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OdataToEntity.EfCore", "..\source\OdataToEntity.EfCore\OdataToEntity.EfCore.csproj", "{94E8BF46-2821-4890-9E07-D1FA5C797C92}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OdataToEntity.Linq2Db", "..\source\OdataToEntity.Linq2Db\OdataToEntity.Linq2Db.csproj", "{54D80D16-BE53-4442-99C8-BA3A8C98A2D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,8 +29,15 @@ Global
{94E8BF46-2821-4890-9E07-D1FA5C797C92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94E8BF46-2821-4890-9E07-D1FA5C797C92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94E8BF46-2821-4890-9E07-D1FA5C797C92}.Release|Any CPU.Build.0 = Release|Any CPU
{54D80D16-BE53-4442-99C8-BA3A8C98A2D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54D80D16-BE53-4442-99C8-BA3A8C98A2D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54D80D16-BE53-4442-99C8-BA3A8C98A2D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54D80D16-BE53-4442-99C8-BA3A8C98A2D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF606C63-D51D-4221-9322-0848DA6687CE}
EndGlobalSection
EndGlobal
16 changes: 11 additions & 5 deletions source/OdataToEntity.Ef6/OdataToEntity.Ef6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
<Import Project="..\..\build\dependencies.props" />

<PropertyGroup>
<Description>Classes bridge from OdataToEntity to Entity Framework 6.1.3. Abstraction layer access to DataContext Entity Framework 6.1.3. Targets .NET 4.6</Description>
<AssemblyTitle>Entity Framework 6 adapter for OdataEntity</AssemblyTitle>
<Description>Entity Framework 6 adapter for OdataEntity</Description>
<Authors>Maxim Voronov</Authors>
<TargetFrameworks>net461</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>portable</DebugType>
<AssemblyName>OdataToEntity.Ef6</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>


<PropertyGroup>
<AssemblyCopyright>LGPL-3.0</AssemblyCopyright>
<AssemblyDescription>Classes bridge from OdataToEntity to Entity Framework 6.2.0. Abstraction layer access to DataContext Entity Framework 6.2.0. Targets .NET 4.6</AssemblyDescription>
<AssemblyTitle>Entity Framework 6 adapter for OdataEntity</AssemblyTitle>
<AssemblyVersion>$(OdataToEntityVersion)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
<PackageId>OdataToEntity.Ef6</PackageId>
<PackageTags>odata;data;services;odatatoentity;ef;entity framework;entity</PackageTags>
<PackageProjectUrl>https://github.com/voronov-maxim/OdataToEntity</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/voronov-maxim/OdataToEntity/blob/master/LICENSE</PackageLicenseUrl>
<PackageVersion>$(OdataToEntityVersion)</PackageVersion>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -36,7 +42,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="EntityFramework" Version="6.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
54 changes: 26 additions & 28 deletions source/OdataToEntity.Ef6/OeEf6EdmModelMetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using OdataToEntity.ModelBuilder;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
Expand All @@ -21,71 +20,70 @@ public OeEf6EdmModelMetadataProvider(DbContext dbContext)
_entityTypes = workspace.GetItems<EntityType>(DataSpace.CSpace).ToDictionary(e => itemCollection.GetClrType(workspace.GetObjectSpaceType(e)));
}

private IEnumerable<EntityType> GetEntityTypes(PropertyDescriptor propertyDescriptor)
private IEnumerable<EntityType> GetEntityTypes(PropertyInfo propertyInfo)
{
EntityType efEntityType;
if (_entityTypes.TryGetValue(propertyDescriptor.ComponentType, out efEntityType))
if (_entityTypes.TryGetValue(propertyInfo.DeclaringType, out efEntityType))
yield return efEntityType;
else
foreach (KeyValuePair<Type, EntityType> pair in _entityTypes)
if (propertyDescriptor.ComponentType.IsAssignableFrom(pair.Key))
if (propertyInfo.DeclaringType.IsAssignableFrom(pair.Key))
yield return pair.Value;
}
public override PropertyDescriptor[] GetForeignKey(PropertyDescriptor propertyDescriptor)
public override PropertyInfo[] GetForeignKey(PropertyInfo propertyInfo)
{
foreach (EntityType efEntityType in GetEntityTypes(propertyDescriptor))
foreach (EntityType efEntityType in GetEntityTypes(propertyInfo))
foreach (NavigationProperty navigationProperty in efEntityType.NavigationProperties)
{
if (!navigationProperty.GetDependentProperties().Any())
continue;

ReferentialConstraint refConstraint = ((AssociationType)navigationProperty.RelationshipType).Constraint;
if (navigationProperty.Name == propertyDescriptor.Name)
if (navigationProperty.Name == propertyInfo.Name)
{
PropertyDescriptorCollection clrProperties = TypeDescriptor.GetProperties(propertyDescriptor.ComponentType);
var propertyDescriptors = new PropertyDescriptor[refConstraint.ToProperties.Count];
var properties = new PropertyInfo[refConstraint.ToProperties.Count];
for (int i = 0; i < refConstraint.ToProperties.Count; i++)
propertyDescriptors[i] = clrProperties[refConstraint.ToProperties[i].Name];
return propertyDescriptors;
properties[i] = propertyInfo.DeclaringType.GetPropertyIgnoreCase(refConstraint.ToProperties[i].Name);
return properties;
}

for (int i = 0; i < refConstraint.ToProperties.Count; i++)
if (refConstraint.ToProperties[i].Name == propertyDescriptor.Name)
return new PropertyDescriptor[] { TypeDescriptor.GetProperties(propertyDescriptor.ComponentType)[navigationProperty.Name] };
if (refConstraint.ToProperties[i].Name == propertyInfo.Name)
return new PropertyInfo[] { propertyInfo.DeclaringType.GetPropertyIgnoreCase(navigationProperty.Name) };
}

return null;
}
public override PropertyDescriptor GetInverseProperty(PropertyDescriptor propertyDescriptor)
public override PropertyInfo GetInverseProperty(PropertyInfo propertyInfo)
{
foreach (EntityType efEntityType in GetEntityTypes(propertyDescriptor))
foreach (EntityType efEntityType in GetEntityTypes(propertyInfo))
foreach (NavigationProperty navigationProperty in efEntityType.NavigationProperties)
if (navigationProperty.Name == propertyDescriptor.Name)
if (navigationProperty.Name == propertyInfo.Name)
{
MetadataProperty metadataProperty;
if (!navigationProperty.ToEndMember.MetadataProperties.TryGetValue("ClrPropertyInfo", false, out metadataProperty))
return null;

var inverseProperty = (PropertyInfo)metadataProperty.Value;
return TypeDescriptor.GetProperties(inverseProperty.DeclaringType)[inverseProperty.Name];
return inverseProperty.DeclaringType.GetPropertyIgnoreCase(inverseProperty.Name);
}

return null;
}
public override int GetOrder(PropertyDescriptor propertyDescriptor)
public override int GetOrder(PropertyInfo propertyInfo)
{
foreach (EntityType efEntityType in GetEntityTypes(propertyDescriptor))
foreach (EntityType efEntityType in GetEntityTypes(propertyInfo))
{
for (int i = 0; i < efEntityType.KeyProperties.Count; i++)
if (efEntityType.KeyProperties[i].Name == propertyDescriptor.Name)
if (efEntityType.KeyProperties[i].Name == propertyInfo.Name)
return i;

for (int i = 0; i < efEntityType.NavigationProperties.Count; i++)
{
int index = 0;
foreach (EdmProperty edmProperty in efEntityType.NavigationProperties[i].GetDependentProperties())
{
if (edmProperty.Name == propertyDescriptor.Name)
if (edmProperty.Name == propertyInfo.Name)
return index;
index++;
}
Expand All @@ -94,24 +92,24 @@ public override int GetOrder(PropertyDescriptor propertyDescriptor)

return -1;
}
public override bool IsKey(PropertyDescriptor propertyDescriptor)
public override bool IsKey(PropertyInfo propertyInfo)
{
foreach (EntityType efEntityType in GetEntityTypes(propertyDescriptor))
foreach (EntityType efEntityType in GetEntityTypes(propertyInfo))
for (int i = 0; i < efEntityType.KeyProperties.Count; i++)
if (efEntityType.KeyProperties[i].Name == propertyDescriptor.Name)
if (efEntityType.KeyProperties[i].Name == propertyInfo.Name)
return true;
return false;
}
public override bool IsNotMapped(PropertyDescriptor propertyDescriptor)
public override bool IsNotMapped(PropertyInfo propertyInfo)
{
foreach (EntityType efEntityType in GetEntityTypes(propertyDescriptor))
foreach (EntityType efEntityType in GetEntityTypes(propertyInfo))
{
for (int i = 0; i < efEntityType.Properties.Count; i++)
if (efEntityType.Properties[i].Name == propertyDescriptor.Name)
if (efEntityType.Properties[i].Name == propertyInfo.Name)
return false;

for (int i = 0; i < efEntityType.NavigationProperties.Count; i++)
if (efEntityType.NavigationProperties[i].Name == propertyDescriptor.Name)
if (efEntityType.NavigationProperties[i].Name == propertyInfo.Name)
return false;
}

Expand Down
36 changes: 0 additions & 36 deletions source/OdataToEntity.Ef6/Properties/AssemblyInfo.cs

This file was deleted.

13 changes: 10 additions & 3 deletions source/OdataToEntity.EfCore/OdataToEntity.EfCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
<Import Project="..\..\build\dependencies.props" />

<PropertyGroup>
<Description>Classes bridge from ODataToEntity to Entity Framework Core. Abstraction layer access to DataContext Entity Framework Core. Targets .NET Core with support for .NET 4.6</Description>
<AssemblyTitle>Entity Framework Core Adapter for OdataEntity</AssemblyTitle>
<Description>Entity Framework Core adapter for OdataEntity</Description>
<Authors>Maxim Voronov</Authors>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>portable</DebugType>
<AssemblyName>OdataToEntity.EfCore</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyVersion>$(OdataToEntityVersion)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
<AssemblyCopyright>LGPL-3.0</AssemblyCopyright>
<AssemblyDescription>Classes bridge from ODataToEntity to Entity Framework Core. Abstraction layer access to DataContext Entity Framework Core. Targets .NET Core with support for .NET 4.6</AssemblyDescription>
<AssemblyTitle>Entity Framework Core adapter for OdataEntity</AssemblyTitle>
<AssemblyVersion>$(OdataToEntityVersion)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
<PackageId>OdataToEntity.EfCore</PackageId>
<PackageTags>odata;data;services;odatatoentity;ef;entity framework core;entity;core</PackageTags>
<PackageProjectUrl>https://github.com/voronov-maxim/OdataToEntity</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/voronov-maxim/OdataToEntity/blob/master/LICENSE</PackageLicenseUrl>
<PackageVersion>$(OdataToEntityVersion)</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions source/OdataToEntity.EfCore/OeEfCoreDataAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public override String EntitySetName
public OeEfCoreDataAdapter() : this(null, null)
{
}
public OeEfCoreDataAdapter(DbContextOptions options) : this(options, null)
{
}
public OeEfCoreDataAdapter(DbContextOptions options, Db.OeQueryCache queryCache)
: this(options, queryCache, new OeEfCoreOperationAdapter(typeof(T), _entitySetMetaAdapters))
{
Expand Down
Loading

0 comments on commit 7593c93

Please sign in to comment.