Skip to content

Commit

Permalink
Fix for #132. Removed arrays from automatic conversion.
Browse files Browse the repository at this point in the history
# Conflicts:
#	Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs
  • Loading branch information
sdanyliv committed Apr 30, 2021
1 parent ebd615c commit 99915a8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ public virtual void DefineConvertors(
if (modelType.IsEnum)
continue;

// skipping arrays
if (modelType.IsArray)
continue;

MapEFCoreType(modelType);
if (modelType.IsValueType && !typeof(Nullable<>).IsSameOrParentOf(modelType))
MapEFCoreType(typeof(Nullable<>).MakeGenericType(modelType));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities
{
public class EntityWithArrays
{
[Key]
public int Id { get; set; }

public Guid[] Guids { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasNoKey();
entity.ToView("EventsView", "views");
});

modelBuilder.Entity<EntityWithArrays>(entity =>
{
});
}

public virtual DbSet<Event> Events { get; set; } = null!;
public virtual DbSet<EntityWithArrays> EntityWithArrays { get; set; } = null!;

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using FluentAssertions;
using LinqToDB.Data;
using LinqToDB.DataProvider.PostgreSQL;
using LinqToDB.EntityFrameworkCore.BaseTests;
using LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -54,6 +56,35 @@ public void TestFunctionsMapping()
}
}


[Test]
public void TestViewMapping()
{
using (var db = CreateNpgSqlEntitiesContext())
{
var query = db.Set<EventView>().Where(e =>
e.Name.StartsWith("any"));

var efResult = query.ToArray();
var l2dbResult = query.ToLinqToDB().ToArray();
}
}

[Test]
public void TestArray()
{
using (var db = CreateNpgSqlEntitiesContext())
{
var guids = new Guid[] { Guid.Parse("271425b1-ebe8-400d-b71d-a6e47a460ae3"),
Guid.Parse("b75de94e-6d7b-4c70-bfa1-f8639a6a5b35") };

var query =
from m in db.EntityWithArrays.ToLinqToDBTable()
where Sql.Ext.PostgreSQL().Overlaps(m.Guids, guids)
select m;

query.Invoking(q => q.ToArray()).Should().NotThrow();
}
}

}
}

0 comments on commit 99915a8

Please sign in to comment.