<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:georss="http://www.georss.org/georss" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
  <channel>
    <title>Nesterovsky bros - Azure</title>
    <link>http://www.nesterovsky-bros.com/weblog/</link>
    <description />
    <language>en-us</language>
    <copyright>Nesterovsky bros</copyright>
    <lastBuildDate>Wed, 20 Oct 2021 16:11:39 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>contact@nesterovsky-bros.com</managingEditor>
    <webMaster>contact@nesterovsky-bros.com</webMaster>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=3042e60d-8943-47f0-9595-0d8e9cfb268c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3042e60d-8943-47f0-9595-0d8e9cfb268c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Lately we work great deal of time with <a href="https://en.wikipedia.org/wiki/Cosmos_DB">Azure's
CosmosDB</a>.
</p>
        <p>
This is how it's defined:
</p>
        <blockquote>
          <i>"It is schema-agnostic, horizontally scalable, and generally classified
as a <a href="https://en.wikipedia.org/wiki/NoSQL">NoSQL</a> database."</i>
        </blockquote>
        <p>
This, unconfident in itself, quote below is clarified as:
</p>
        <blockquote>
          <i>"The SQL API lets clients create, update and delete containers and
items. Items can be queried with a read-only, JSON-friendly SQL dialect."</i>
        </blockquote>
        <p>
To be honest this SQL API made us favor CosmosDB.
</p>
        <p>
So, we started a development with CosmosDB as a data storage.
</p>
        <p>
The next development ingredient we learned the hard way is to try to refrain from
clever techniques. 
</p>
        <p>
The lesson we learned is simple: after you finish with a project, provided it's
not a toy, you give it to people who will be supporting it. You should think about
those future developers before you're going to insert some cleverness in you code.
</p>
        <p>
With this common sense we selected <a href="https://en.wikipedia.org/wiki/Entity_Framework">EF
Core</a> as a library that will serve as an interface between C# and the database.
</p>
        <p>
Initialy all went well until we needed to store a list of strings as a document property
and found it's not possible.
</p>
        <p>
Why? - was a naive question.
</p>
        <p>
Answer puzzled us a lot - because string is not an "Entity" (what ever it
means), and EF is about framework of entities.
</p>
        <p>
You could argue with this argument as long as you like, it just does not work. It
is especially bad if you need to store a class that you do not directly control e.g.
structures returned from other services.
</p>
        <p>
Next pothole with EF was when we tried to run an innocent query that joins the data
from document: e.g. document contains items, and you want to query some items from
some documents.
</p>
        <p>
Guess what?
</p>
        <p>
Right, EF Core does not support it.
</p>
        <p>
Why?
</p>
        <p>
Because!
</p>
        <p>
Later we have found that many other constructs and functions that you easily use in
SQL dialect of CosmosDB are not possible or supported in EF Core.
</p>
        <p>
We were very upset with those crutches and came to a conclusion that EF Core harms
more than helps when you work with CosmosDB.
</p>
        <p>
We went on and looked at how you work directly with CosmosDB client, and have found
that it has all features ready:
</p>
        <ul>
          <li>
you may give it SQL and bind parameters;</li>
          <li>
you may convert result items to objects;</li>
          <li>
you may create, delete, update and query data;</li>
        </ul>
        <p>
So, do we need EF Core? 
</p>
        <p>
We answered, no.
</p>
        <p>
This does not mean we reject the value of EF Core but here our conclusion was that
this API layer just complicated things instead making them simpler. It might be that
EF Core for CosmosDB is not mature enough at this time.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3042e60d-8943-47f0-9595-0d8e9cfb268c" />
      </body>
      <title>CosmosDB with EF Core</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2021/10/20/CosmosDBWithEFCore.aspx</link>
      <pubDate>Wed, 20 Oct 2021 16:11:39 GMT</pubDate>
      <description>&lt;p&gt;
Lately we work great deal of time with &lt;a href="https://en.wikipedia.org/wiki/Cosmos_DB"&gt;Azure&amp;#39;s
CosmosDB&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
This is how it&amp;#39;s defined:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;"It is schema-agnostic, horizontally scalable, and generally classified
as a &lt;a href="https://en.wikipedia.org/wiki/NoSQL"&gt;NoSQL&lt;/a&gt; database."&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This, unconfident in itself, quote below is clarified as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;"The SQL API lets clients create, update and delete containers and
items. Items can be queried with a read-only, JSON-friendly SQL dialect."&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
To be honest this SQL API made us favor CosmosDB.
&lt;/p&gt;
&lt;p&gt;
So, we started a development with CosmosDB as a data storage.
&lt;/p&gt;
&lt;p&gt;
The next development ingredient we learned the hard way is to try to refrain from
clever techniques. 
&lt;/p&gt;
&lt;p&gt;
The lesson we learned is simple: after you finish with a project, provided it&amp;#39;s
not a toy, you give it to people who will be supporting it. You should think about
those future developers before you&amp;#39;re going to insert some cleverness in you code.
&lt;/p&gt;
&lt;p&gt;
With this common sense we selected &lt;a href="https://en.wikipedia.org/wiki/Entity_Framework"&gt;EF
Core&lt;/a&gt; as a library that will serve as an interface between C# and the database.
&lt;/p&gt;
&lt;p&gt;
Initialy all went well until we needed to store a list of strings as a document property
and found it&amp;#39;s not possible.
&lt;/p&gt;
&lt;p&gt;
Why? - was a naive question.
&lt;/p&gt;
&lt;p&gt;
Answer puzzled us a lot - because string is not an &amp;quot;Entity&amp;quot; (what ever it
means), and EF is about framework of entities.
&lt;/p&gt;
&lt;p&gt;
You could argue with this argument as long as you like, it just does not work. It
is especially bad if you need to store a class that you do not directly control e.g.
structures returned from other services.
&lt;/p&gt;
&lt;p&gt;
Next pothole with EF was when we tried to run an innocent query that joins the data
from document: e.g. document contains items, and you want to query some items from
some documents.
&lt;/p&gt;
&lt;p&gt;
Guess what?
&lt;/p&gt;
&lt;p&gt;
Right, EF Core does not support it.
&lt;/p&gt;
&lt;p&gt;
Why?
&lt;/p&gt;
&lt;p&gt;
Because!
&lt;/p&gt;
&lt;p&gt;
Later we have found that many other constructs and functions that you easily use in
SQL dialect of CosmosDB are not possible or supported in EF Core.
&lt;/p&gt;
&lt;p&gt;
We were very upset with those crutches and came to a conclusion that EF Core harms
more than helps when you work with CosmosDB.
&lt;/p&gt;
&lt;p&gt;
We went on and looked at how you work directly with CosmosDB client, and have found
that it has all features ready:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
you may give it SQL and bind parameters;&lt;/li&gt;
&lt;li&gt;
you may convert result items to objects;&lt;/li&gt;
&lt;li&gt;
you may create, delete, update and query data;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
So, do we need EF Core? 
&lt;/p&gt;
&lt;p&gt;
We answered, no.
&lt;/p&gt;
&lt;p&gt;
This does not mean we reject the value of EF Core but here our conclusion was that
this API layer just complicated things instead making them simpler. It might be that
EF Core for CosmosDB is not mature enough at this time.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3042e60d-8943-47f0-9595-0d8e9cfb268c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,3042e60d-8943-47f0-9595-0d8e9cfb268c.aspx</comments>
      <category>Azure</category>
      <category>Thinking aloud</category>
    </item>
  </channel>
</rss>