We're trying to use EF6 + CodeFirst with a PostGIS database.
PostgreSQL v9.3.10
PostGIS v2.1.3
npgsql v3.2.2.0
EntityFramework6.Npgsql v3.1.1.0
My simple models without geometries work fine with Add-Migrations but when I add a DbGeometry property Add-Migrations fails with
Not supported edm type: Edm.Geometry
at Npgsql.NpgsqlProviderManifest.GetStoreType(TypeUsage edmType)
at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, String columnName, Boolean isInstancePropertyOnDerivedType)
Googling I found these post at the GitHub of npgsql:
https://github.com/npgsql/npgsql/issues/623 and
https://github.com/npgsql/EntityFramework6.Npgsql/issues/18
These posts are from May 2015. I can't imagine nobody has found a solution yet for this problem. We can't be the first team in years that is doing EF6+CodeFirst with PostGIS.
So please advice how to continue or suggest a different provider which is working.
Related
I have a rails project that I need to implement a search box in my project , I decide to use elastic search because performance speed of the query in comparison to SQL query it's important . In this project it's important that user could define type of condition like " < , > != , = " .I ask
question
and someone told me that I could use query string to solve these issues. but I have no idea how could I implement in my project this type of query.
In my project, I use two elasticsearch gems, "elasticsearch-rails" and "elasticsearch-model" and follow this tutorial
for implementation in my project but it's not useful for this issues.
could you please tell me how could I implement query string on the rails project?
This is how you run a query_string on RoR :
Article.search(query: { query_string: { query: "(new york city) OR (big apple)"} })
I just read you want to execute SQL queries on ES. That can be done out of the box using the SQL API.
I found the implementation for elasticsearch-ruby here :
https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-xpack
On this file exactly
https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/sql/query.rb
And this is the documentation about
https://rdoc.info/gems/elasticsearch-xpack/Elasticsearch%2FXPack%2FAPI%2FSQL%2FActions:query
I am using Postgres + EF Core. I have a column called Name which I want to be unique. I have tried the following:
builder.HasIndex(s => s.Name).IsUnique();
but this allows "test123" and "TEST123" to be accepted. How can I add a case insensitive unique constraint with fluent api?
Or do I just need to create a NormalizedName column and add the unique constraint to that. Seems like a lot of work every time I want to add a unique constraint to a column.
If you're using EF Core 5.0, then see below (probably the better solution). Otherwise, I added a case insensitive check by making use of the citext extension as described here. There are some limitations, I won't list them here but you can read up on them in the previous link or directly on the PostgreSQL Docs.
Also ensure you have the postgres-contrib package installed to make use of this extension.
First, enable the extension by adding it to your model builder
modelBuilder.HasPostgresExtension("citext");
Then use the citext as the column type
builder.Property(s => s.Name)
.HasColumnType("citext")
EF Core 5.0
With EF Core 5.0 there's better support by making use of Collations. You can also check out the Npgsql docs in regards to PostrgeSQL. This gets over a bunch of limitations with citext above and gives you a lot more control.
So the (untested) steps are:
Create a collation as a database object using ICU. This will create a non-deterministic, case-insensitive ICU collation. If you need something else, check out the ICU docs.
modelBuilder.HasCollation("case_insensitive_collation", locale: "en-u-ks-primary", provider: "icu", deterministic: false);
Now on you column, you can add:
builder.HasIndex(s => s.Name)
.UseCollation("case_insensitive_collation")
.IsUnique();
If you achieved it some other way, I'd love to hear how.
I'm trying to integrate my Oracle Database into my ASP.NET app, but I keep getting this error :
Error 2002: The EntityContainer 'OracleDBTargetContainer' for the
storage model specified as part of this MSL does not exist in
MetadataWorkspace.
I've tried everything I could think of but still can't figure out what's wrong.
What can I do to diagnose the root cause of this?
This is still new to me so I might miss something very obvious.
I'm assuming it my not like my database as the Diagram displayed when I integrated another DB. I've checked the foreign keys, primary keys, ... but to no good.
Using VS2013 with ODP.NET 12c Release 3.
EDIT : My EntityContainerMapping is empty, is that normal?
<EntityContainerMapping CdmEntityContainer="PMModelContainer" StorageEntityContainer="PMModelTargetContainer"></EntityContainerMapping>
I found what was wrong.
One of my foreign key didn't match the primary key (Number 20 instead of Number 10)
I saw on stack overflow that it could be a problem and checked my tables but I missed that one obviously.
How did I realize it ? Well because rather than creating the EF Designer, I chose the Code First from database option, and, oh, what do you know, the error message now tells you EXACTLY what the problem is ! (Table names and columns).
I have a web application with a EF model which I originally designed using a SQL Server 2008 backend. Later on, I decided to use SQL CE for portability, so I converted the model to target Sql CE 4.0. However, I am running into serious performance issues when running this app.
For example, I have a portion in code that retrieves an entity from the database:
Trace.Write("Retrieving node from database", "Application");
var name = value.ToString();
var node = DataContext.Entities.Nodes
.SingleOrDefault(n => n.Name == name);
Trace.Write("Node retrieved from database ", "Application");
When I look at the trace information (trace.axd), those lines of code take a wooping 0.6 seconds!!
Trace Information
Category Message From First(s) From Last(s)
Application Retrieving node from database 0.00057591118424269 0.000576
Application Node retrieved from database 0.595122564460008 0.594547
And this happens everywhere in my application where I query by Name.
Any ideas? I'm guessing I have to define an index on the column, but how would I do that in the EF model?
EDIT : Gramma
EDIT 2: Spelling in Title
I have a sample with some performance advice here, using global.asax: http://erikej.blogspot.com/2011/01/entity-framework-with-sql-server.html and other performance tips here: http://blogs.msdn.com/b/wriju/archive/2011/03/15/ado-net-entity-framework-performance-tips.aspx
I've used the older versions of SQL CE in the past, and I've found that one major bottleneck is opening the connection.
You might try managing the open connection on your own, and passing it into the data context by hand (rather than allowing the context to automatically manage the connection.)
Seems my appreciation for the Entity Framework is taking a serious hit. The "MS almost got it right, but they just missed it because of something L-A-M-E" thought is coming up. Until today everything has been fine. For some unknown reason, it won't compile anymore with Error 2048. I've read up on this and I've seen how you need to map all three operations. Why is this even necessary? What I if I don't need a delete function and only need insert and update? I tried mapping a dummy SP to my delete function. If that fixes my problem, however cheezy, fine. Only problem is, it just created more problems.
Here's what I have. I'm writing a simple newsletter app in MVC. I have entities for a publication, issue and article all generated from my DB (SQL 08). I set up the the relationships in my DB and they translated fine to my EDMX. I made some SPs to insert and update my issues and article. I added them to the EDMX and mapped them accordingly. I don't need a delete function for any of them and I don't need anything for the publication entity. Why is the compiler forcing me to map all functions? IMO, this a MAJOR, MAJOR PROBLEM with EF4 and I can't believe MS would release it with this kind of crap coming up.
The other strange issue is I've tried mapping sp's to entities in another project and configured with only insert and update and they compile fine. Why is the compiler inconsistent?
I would rather not resort to having to use the Imported Functions. Is that my only option? If that's the case it eliminates the ability to the SaveChanges method. Come On MS!!! Fix this!!!!!!!
After much digging and side by side text comparison, I think I have found the solution.
The SP in question was set up like
CREATE PROCEDURE updateArticle
(
#ArticleID INT,
#Content TEXT
)
where it should have been something like
CREATE PROCEDURE updateArticle
(
#ArticleID INT,
#IssueID INT,
#Content TEXT
)
Now, I still don't know why EF4 even requires this since I'm not updating the issueid and the error message lends little help in diagnosing the problem. My SP doesn't even use the IssueID, but EF needs it regardless. Hopefully this will help someone down the road. MS still could do a better job regarding the need for this.