Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating query for PostGIS datatypes #3

Closed
kostat opened this issue Jun 29, 2020 · 4 comments
Closed

Error generating query for PostGIS datatypes #3

kostat opened this issue Jun 29, 2020 · 4 comments

Comments

@kostat
Copy link
Contributor

kostat commented Jun 29, 2020

I got some error when one of my column data types were of type geometry/geography, and it was unable to generate the query for me. Below was my code that i was using to generate my query and the Deadhead entity.

 [Table("deadhead")]
    public partial class Deadhead
    {
        [Column("origin_lon", TypeName = "numeric")]
        public decimal OriginLon { get; set; }
        [Column("origin_lat", TypeName = "numeric")]
        public decimal OriginLat { get; set; }
        [Column("destination_lon", TypeName = "numeric")]
        public decimal DestinationLon { get; set; }
        [Column("destination_lat", TypeName = "numeric")]
        public decimal DestinationLat { get; set; }
        [Column("distance", TypeName = "numeric")]
        public decimal Distance { get; set; }
        [Key]
        [Column("key", TypeName = "character varying")]
        public string Key { get; set; }
        [Column("origin_point")]
        public NpgsqlPoint? OriginPoint { get; set; }
        [Column("destination_point")]
        public NpgsqlPoint? DestinationPoint { get; set; }
        [Column("origin_geog", TypeName = "geography")]
        public Geometry OriginGeog { get; set; }
        [Column("destination_geog", TypeName = "geography")]
        public Geometry DestinationGeog { get; set; }
    }

db.Deadhead.Query((Deadhead deadhead) =>
{
var view = deadhead.@using((deadhead.Key, deadhead.OriginLon, deadhead.OriginLat, deadhead.DestinationLon, deadhead.DestinationLat, deadhead.Distance, deadhead.OriginPoint, deadhead.DestinationPoint, deadhead.OriginGeog, deadhead.DestinationGeog));
INSERT().INTO(view);
VALUES(view.RowsFrom(upsertData));
ON_CONFLICT((deadhead.OriginLon, deadhead.OriginLat, deadhead.DestinationLon, deadhead.DestinationLat)).DO_NOTHING();
return RETURNING(deadhead);
});
@vaibhavpingle
Copy link

vaibhavpingle commented Jun 30, 2020

@kostat Thank you for creating this issue. Here is the exception that I see when I am inserting a new record:

DeadheadMiles.DataModel.DeadheadRepository: Error: UpsertDeadhead Error: System.InvalidOperationException: Cannot translate property: DeadheadMiles.DataModel.DBContext.Deadhead.get_OriginGeog. Ensure the type DeadheadMiles.DataModel.DBContext.Deadhead is mapped. Note, that ELINQ custom methods must be either static, interface default or attributed with [Local]
   at A.b.A(MethodInfo , Type )
   at A.b.M.c()
   at A.b.f.c(Func`1 )
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.String.JoinCore[T](Char* separator, Int32 separatorLength, IEnumerable`1 values)
   at System.String.Join[T](String separator, IEnumerable`1 values)
   at A.b.T.A()
   at A.b.M.A(Func`1 , Int32 )
   at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable`1 source, Func`3 selector)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at A.b.M.c()
   at A.b.F.A()
   at A.b.w.A()
   at A.c.B`2.A()
   at A.b.i.A()
   at Streamx.Linq.SQL.EFCore.EFCoreExtensions.GetQuerySQL[TDelegate](IInfrastructure`1 source, TDelegate query, Object[]& params)
   at Streamx.Linq.SQL.EFCore.EFCoreExtensions.A[A](DatabaseFacade , A )
   at Streamx.Linq.SQL.EFCore.EFCoreExtensions.Execute[TEntity](DatabaseFacade source, Action`1 query)

Here I how i am injecting the EF Context:

            services.AddDbContext<DeadheadContext>(options =>
            {
                options.UseNpgsql(configuration.GetConnectionString("Deadhead"), o => o.UseNetTopologySuite());
                options.EnableSensitiveDataLogging();
                options.UseLoggerFactory(new LoggerFactory(new List<DebugLoggerProvider> { new DebugLoggerProvider() }));
                Streamx.Linq.SQL.EFCore.ELinq.Configuration.RegisterVendorCapabilities();
            }, ServiceLifetime.Transient);

There was a similar error trying to read a ValueTuple<Nullable<NpgsqlPoint>> datatype as ELinq could not recognize the translation. Probably a similar issue.

@kostat
Copy link
Contributor Author

kostat commented Jun 30, 2020

Should be fixed in https://www.nuget.org/packages/Streamx.Linq.SQL.EFCore/3.1.14
ELinq wrongly assumed that Geometry is another entity and tried to find an association (FK) instead of a normal column.

@vaibhavpingle
Copy link

Awesome! I will update and verify. By the way Kudos for building this.

@kostat
Copy link
Contributor Author

kostat commented Jul 7, 2020

Thanks. Assuming the issue is fixed - closing.

@kostat kostat closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants