What is the best way to work with a Cosmos Document db? EF Core vs Cosmos SDK - entity-framework

Microsoft provides two ways of working with cosmos dbs in C#/.NET.
One can either use Entity Framework(EF) Core, which makes use of the cosmos SDK behind the scenes and allows you to use EF with Cosmos.
This last point could be seen as positive or negative depending on if you want to use EF vs Dapper or whatever, but for my use case, I would prefer to use EF unless given a good reason not to.
Microsoft themselves has not made any statement I can find on which should be used or why. (I Assume this is a .NET Core project)

EF Core works only for SQL API of Cosmos DB as of now. So, If you are using other APIs, you cannot use EF Core.
Also, Take a look at other limitations of EF Core Azure Cosmos DB Provider Limitations at https://learn.microsoft.com/en-us/ef/core/providers/cosmos/limitations
We used Cosmos DB SDK which is quite flexible and the performance is also good.

After an experience with Cosmonaut package, EF Core and SDK I have to say that Ef Core is focused on relational mapping. Witch Document DB you need to focus on Json serialization. Ef Core model configuration feels cumbersome and limiting for document DB interaction - You have to configure things that just works while serializing. Both Cosmonaut and SDK allow focusing on serialization which in most cases just works. Cosmonaut is a convenient facade on top of SDK - but looks dead at the moment so I recommend SDK.

Related

Why does not Entity Framework Core have an Upsert (AddOrUpdate) and Synchronize(AddOrUpdateOrDelete) command?

I faced a situation where I need to maintain some database tables in sync with a Rest API. There is a daemon that keeps hitting this endpoint and has to sync the related tables.
I'm using ef core and I found only the standard Add and AddRange methods but nothing like Upsert or Synchronize. I searched a little bit and found that some proprietary nugget packages provide this but I need something open-source.
Is there a reason why this is not supported directly in EF Core ?

Using entity framework with cassandra database

I am working on a new project which is to use Asp.net MVC 5 and Cassandra.
I am very OK working with entity framework.
Is there a way of connecting entity framework to a Cassandra database?
If not, can anyone help me with the necessary structures to have my MVC 5 application work with a Cassandra database?
More especially is the fact that i want to work with the MVC 5 identity.
I'll really appreciate any help.
All the old versions of EF, up to version 6.x, don't support NoSQL databases like Cassandra.
EF7 is still under development, but it's being designed to be flexible enough to support NoSQL databases. As of today, (Nov 2015) there isn't still any support for a NoSQL database in the current EF7 beta8. But we can expect to see it in the future.
For example you can see it mentioned in this article of MSDN magazine: Looking ahed to Entity Framework 7:
Beyond Relational
When Entity Framework was first introduced, Microsoft had a vision of it being used for a variety of data stores, though the first pass focused on relational databases. Non-relational databases existed at that time, but were not widely used, unlike the NoSQL databases—especially document databases—that are so popular today.
While EF is an Object Relational Mapper (ORM), developers who use it want to be able to use the same constructs to interact with non-relational databases. EF7 will provide a high level of support for this, but keep in mind what high level really means. There are vast differences between relational databases and non-relational databases and EF will not make any attempt to mask those differences. But for basic querying and updates, you’ll be able to use the patterns with which you’re already familiar.

Entity Framework 6.1.3 code first fluent mappings compatible database on mono

I have a Asp.Net webapi 2 system that works with sql server. I developed it using entity fraework 6.1.3 code first data models and fluent mappings with the typical workflow of add-migration/update-database. I love it.
I have a need to create the exact same software with a lighter weight db to run on a raspberry pi device. It's the disconnected version of the software that will replay/resync all of its data to the cloud version (sql server).
I realize I may need to relax some of my constraints, but starting at the extreme, I would like to target the exact same code base with something like sqlite and xcopy deploy it to my raspberry pi and run in on mono under kestrel web server.
Ideally, I'd just like to change my connection string to point to an empty sqlite db, do a update-database and have the exact same software initially run on my windows development box (and then xcopy it over).
I have read a lot about sqlite entity framework support but a) it doesn't seem to support migrations b) it doesn't seem to support fluent mapping
I could get by using a tool to convert my sql server db to sqlite (every time I change schema) and thus avoid the need to update-database. But the lack of fluent mappings would still prevent the data model to be properly mapped to the existing sqlite schema.
Does anybody have some thoughts/recommendation for sqlite that my help me accomplish my goals?
Do you have any other database recommendations that would help me accomplish my goals - for instance I looked at vistadb, but I don't think they support fluent either.
The devart sqlite driver seems to support everything I need but their examples are all old school and AFAIK they don't have one single example that is a modern code first model with fluent mappings. And even if they did fully support code first wth fluent I am concerned there would be some syntax differences and I am not sure my existing sql server targeting code would be compatible with it. I asked the question on their forums and sent an email but haven't received a response yet.
Thanks
You could consider using EF7, which is a API compatible new version of Entity Framework, that fully supports migrations and fluent mappings with SQLite. EF7 runs on .NET 4.6 and .NET Core. Depending on what features in EF6 you use, it could be an easy upgrade, in particular since you already use Code First.
http://ef.readthedocs.org/en/latest/getting-started/linux.html

Is it feasible to build company specific framework that wraps NHibernate?

I heard that companies that use Java technologies, they used to build their own custom Framework that wraps Hibernate. However, is it really feasible for their .Net peers to do the same thing with NHibernate or Entity Framework?
This is almost always a horrible idea - I think Ayende sums it up best in this article. In general, you should consider NHibernate itself to be the "wrapper" around your data access - attempting to build an abstraction layer on top of it is probably going to be a losing proposition.
Actually, you should check out some of the articles on .NET Junkie's weblog. He wrote several great posts on how to deal with repositories, queries, commands and so on. We've been using these in a very large enterprise system where we switch between an in-memory dictionary, an in-memory SQLite database and a production environment using SQL Server or Oracle. Obviously, we use NHibernate for this.
I use the repository pattern and a separate project/dll to abstract away the data framework nhibernate / entity framework. this is a good starting point http://codebetter.com/petervanooijen/2008/04/04/wrapping-up-nhibernate-in-repositories/

How to use Entity framework for MS Access database

I have to develop a desktop windows application in C#.Net 4.0 that will run in three different databases ie. MS Access 2007 onwards, Oracle 11G, and SQL Server 2008. Now I want to use Entity Framework in my application. Is this a best choice to use EF for my application ?
If yes, then how can I use entity framework for Access database?
Thanks in Advance.
You can use the EF with Microsoft Access using an Entity Framework provider for Microsoft Access.
You can find an EF provider for Access
https://github.com/bubibubi/JetEntityFrameworkProvider
See this answer. Ask yourself why you need Access, could you use SQL Express instead? If you absolutely need Access then it would seem EF is not the right choice in this instance.
Putting Access to one side for the moment, it's perfectly possible to change data providers with EF (particularly code-first) as EF abstracts a lot of the database goo away from your code; depending on the database design it could be as simple as changing the connection string dynamically. The practical implications of this really do depend on your database design and the nature and complexity of the application you are building. See this question for example, here's another example.
We use Dapper as our ORM with repositories when working with MS Access. It's fantastic.