Exception querying remote database with an EF Core assembly connection that uses NetTopologySuite
Sorry, this is a bit of a specific question, I can't connect to a remote database using an EF Core connection.
I have an ASP.NET Core app that uses EF Core, and the NetTopologySuite Nuget package. Previously, I was able to connect to both my local SQL Server database and the remote database that backs the deployed app. My two connections both used the .NET assembly on my local machine, only the connection string was different.
Since upgrading to LP9, when I try to connect to the remote database, I get the following exception...
The property 'Point.UserData' could not be mapped because it is of type 'object', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Connecting to the local database works fine.
Although the obvious culprit is LP9, I get the same exception in LP8, although it used to work fine there.
Anyone any idea why this is happening?
Best Answer
-
Solved.
My AppDbContext contained the following...
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!string.IsNullOrWhiteSpace(_connectionString)) { optionsBuilder.UseSqlServer(_connectionString, x => x.UseNetTopologySuite()); } if (AppDomain.CurrentDomain.FriendlyName.StartsWith("LINQPad")) { optionsBuilder.UseLazyLoadingProxies(); } }I changed this to...
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { if (!string.IsNullOrWhiteSpace(_connectionString)) { optionsBuilder.UseSqlServer(_connectionString, x => x.UseNetTopologySuite()); } } else { optionsBuilder.UseSqlServer(x => x.UseNetTopologySuite()); } if (AppDomain.CurrentDomain.FriendlyName.StartsWith("LINQPad")) { optionsBuilder.UseLazyLoadingProxies(); } }...and it works.