Skip to content

Commit

Permalink
fk working
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Porro committed Jan 29, 2024
1 parent 455c689 commit a9f4ce9
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public EntityMapper CreateMapper(DbContext dbContext, object profileKey)

mapperOptions.TypeConventions.Add(new EntityTypeConventions(dbContext.Model));
mapperOptions.TypeMapperFactories.Add(new EntityTypeMapperFactory());
mapperOptions.TypeMapperFactories.Add(new KeyToEntityTypeMapperFactory());
//mapperOptions.TypeMapperFactories.Add(new KeyToEntityTypeMapperFactory());

return new EntityMapper(mapperOptions, entityMapperOptions.JsonOptions);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Detached.Mappers.EntityFramework.TypeMappers
{
public class CompositionEntityTypeMapper<TSource, TTarget, TKey> : EntityTypeMapper<TSource, TTarget, TKey>
where TSource : class
where TTarget : class
where TKey : IEntityKey
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class EntityTypeMapperFactory : ITypeMapperFactory
{
public bool CanCreate(Mapper mapper, TypePair typePair)
{
return typePair.TargetType.IsEntity()
return (typePair.SourceType.IsComplexOrEntity() || typePair.SourceType.IsPrimitive())
&& typePair.TargetType.IsEntity()
&& typePair.TargetType.IsConcrete();
}

Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/Detached.Mappers.Json/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class Package
{
public static MapperOptions WithJson(this MapperOptions mapperOptions)
{
mapperOptions.TypeFactories.Add(new JsonTypeOptionsFactory());
mapperOptions.TypeFactories.Add(new JsonTypeFactory());
mapperOptions.TypeMapperFactories.Add(new JsonTypeMapperFactory());
return mapperOptions;
}
Expand Down
28 changes: 0 additions & 28 deletions src/Detached.Mappers.Json/TypeOptions/JsonTypeOptionsFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonArrayTypeOptions : IType
public class JsonArrayType : IType
{
public Type ClrType => typeof(JsonArray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonNodeTypeOptions : IType
public class JsonNodeType : IType
{
public JsonNodeTypeOptions()
public JsonNodeType()
{
this.Abstract(true);
}
Expand All @@ -31,7 +31,7 @@ public Expression BuildNewExpression(Expression context, Expression discriminato

public ITypeMember GetMember(string memberName)
{
return new JsonObjectMemberOptions(memberName);
return new JsonObjectMember(memberName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonObjectMemberOptions : ITypeMember
public class JsonObjectMember : ITypeMember
{
readonly string _memberName;

public JsonObjectMemberOptions(string memberName)
public JsonObjectMember(string memberName)
{
_memberName = memberName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonObjectTypeOptions : IType
public class JsonObjectType : IType
{
public Type ClrType => typeof(JsonObject);

Expand All @@ -28,7 +28,7 @@ public Expression BuildNewExpression(Expression context, Expression discriminato

public ITypeMember GetMember(string memberName)
{
return new JsonObjectMemberOptions(memberName);
return new JsonObjectMember(memberName);
}
}
}
28 changes: 28 additions & 0 deletions src/Detached.Mappers.Json/Types/JsonTypeFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Detached.Mappers.Types;
using System;
using System.Text.Json.Nodes;

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonTypeFactory : ITypeFactory
{
readonly IType _nodeOptions = new JsonNodeType();
readonly IType _arrayOptions = new JsonArrayType();
readonly IType _objectOptions = new JsonObjectType();
readonly IType _valueOptions = new JsonValueType();

public IType Create(MapperOptions options, Type clrType)
{
if (typeof(JsonArray).IsAssignableFrom(clrType))
return _arrayOptions;
else if (typeof(JsonObject).IsAssignableFrom(clrType))
return _objectOptions;
else if (typeof(JsonValue).IsAssignableFrom(clrType))
return _valueOptions;
else if (typeof(JsonNode).IsAssignableFrom(clrType))
return _nodeOptions;
else
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Detached.Mappers.Json.TypeOptions
{
public class JsonValueTypeOptions : IType
public class JsonValueType : IType
{
public Type ClrType => typeof(JsonValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public bool CanCreate(Mapper mapper, TypePair typePair)
&& typePair.TargetType.IsCollection()
&& !typePair.TargetType.IsAbstract())
{
IType sourceItemType = mapper.Options.GetType(typePair.TargetType.ItemClrType);
//IType sourceItemType = mapper.Options.GetType(typePair.SourceType.ItemClrType);
IType targetItemType = mapper.Options.GetType(typePair.TargetType.ItemClrType);

return targetItemType.IsEntity() && (sourceItemType.IsComplexOrEntity() || sourceItemType.IsPrimitive());
return targetItemType.IsEntity();
}

return false;
Expand Down
Loading

0 comments on commit a9f4ce9

Please sign in to comment.