LiteDB: Are Projections supported? - c#

I'm trying to evaluate whether I can use LiteDB for one of my projects. I love MongoDB for its query capabilities and for the projections. See: Mongo Documentation
The problem is, that I want to use a database that doesn't need a dedicated server process, so I looked out for LiteDB as it stores the database in just one file and has a similar approach like MongoDB.
Until now I haven't found documentation about the possibility to perform projections while querying. So does someone have experience with this and can tell me if that is possible?

Related

Vendor-agnostic way of retrieving the schema of a database table

I'm currently building an application at work where users get to define various ways in which pieces of data are routed to various storage technologies. Those include traditional relational database systems.
We'd like to give feedback to users if the way they've configured this does not work with the defined database schema, i.e. if the column types don't match.
I've been looking for a solid vendor-agnostic way of retrieving the datatypes of a database table, ideally including the CLR types they map to.
So far I've struggling to find anything even remotely decent. Much of the solutions I stumbled upon are not vendor-agnostic, and much of the tooling regarding database technologies included in .NET (Core) are specific to SQL Server.
The most popular way seems to be via the GetSchema method on an IDbConnection object, but that one is also riddled with implementation specific details, and does not give a very pleasant to use result. I've been able to retrieve textual representations for each of the types, and for Postgres for example, the closest I've come is actual human-readable descriptions of the types. VARCHAR was displayed as "Varying length character string", which is hard to parse.
Most database interaction libraries for .NET (Core) abstract away the primitives like DataSet, DataTable, DataReader etc, and usually directly map to objects, thereby removing any use I could have had for them.
What is the easiest way to get an overview of a table schema?
For clarity's sake, we're looking to support the following database technologies for now:
SQL Server
PostgreSQL
MySQL / MariaDB
SQLite
Oracle RDMBS
Thanks!
This does sound like something that you have to pay for, because it is such a narrow use-case, if it even exists. I have a hard time believing this would be a maintained open-source project.
When that is said, maybe you can go around it by querying the database directly using something like this:
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tableName'
Taken from https://stackoverflow.com/a/18298685/1387545
I checked and it seems to work for at least the first two databases. I think finding some kind of SQL query is your best bet of a generic solution. Since SQL is the technology that they share.
But then again, I think you will obtain a better result by building your own specific parser for the database tables for each database. It of course all depends on time and budget.

How to use entity framework with elastic search

I want to use on entity framework with elastic search.
I saw this article MVC APPLICATION WITH ENTITY FRAMEWORK AND ELASTICSEARCH.
But as I understood, I need 2 DB (ms sql+ elastic) and there they explain how to translate the data.
The ms sql I will save the data and I done the search on the elastic .
So all the data will be twice so it will be waste of storage...
Is there any direct way to do that?
thanks
You can use entity framework with elastic search by utilising ElasticsearchCrud api.
This article clearly explains the steps to do so.
P.S: I rather not to copy/paste the steps here as it might look redundant.
Yes you understood right you would need to use two different sources.
There is no direct way to use elasticsearch with EF, you would need to write you custom logic to fit Database and Elasticsearch together.
If you ask why? Answer is that Database and Elasticsearch are different.
First of all Elastic is document database and you should save whole object while in database you can split items to multiple tables in ES "preferable" to save as a one document (Still in ES you can use nested objects but you will not be able to join).
Secondly search queries are totally different in SQl and Elastic. So sometimes only you would decide which source should be used to search. To search Elastic you can use NEST package but you would need to learn ES queries and indexing part since depends on analysis you will have defferent results.

What advantages does MongoDB offer over ElasticSearch as a NoSQL database only

I'm quite new to NoSql databases, but I'm really lovin' MongoDB with the official c# driver. It's currently the backend to an MVC application I'm writing, and the simplicity AND speed make my life way way easier.
However I've come to that point in the application where I need really great search. I used to use Solr, but have become quite interested in ElasticSearch.
ElasticSearch, as far as I can tell (from a very superficial level), can do everything MongoDB can in terms of being a document database.
So, if I'm already using a NoSql db, and I need great search, is there any point in Mongo? What's the use case?
Is Mongo faster? Easier to use? Is it the BSON datatypes and drivers? Why not use ElasticSearch as my DB?
I'm currently using AppHarbor and lovin' "The Cloud". I hate IT and want to focus on my application only. With that said, the only advantage I see so far is:
There are already a number of "Cloud" MongoDB providers. With ElasticSearch I've got to set it all up myself.
This is a very good question. I have asked myself the same question and came up with the following answer.
ElasticSearch doesn’t have a good way to backup data. As an example, do a quick search for “ElasticSearch backup” and one for “mongodb backup”. MongoDB has tools and documentation on how to backup data. While there is documentation on how to backup ElasticSearch data, this documentation doesn’t seem as mature.
In general, MongoDB has much better documentation. In particular its admin documentation is much better than ElasticSearch.
MongoDB provides commercial support. You might not care about commercial support at the moment, but it is nice to know it is available.
MongoDB has MapReduce built in, ElasticSearch does not. This may not be a big thing, but worth noting.
My personal opinion is that I wouldn’t use ElasticSearch if you cannot afford to lose data. I could see using ElasticSearch as a primary data store for something requiring real-time analytics, but did not have any long-term data retention requirements. Otherwise, I would suggest using MongoDB and ElasticSearch together. There is a MongoDB River Plugin for ElasticSearch. This makes it pretty easy to update the ElasticSearch index automatically.

How to use a local database in c#?

I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));

ORM, C# and MySQL - Take2

This questions actually refers to another one already asked, now I want to reformulate it :)
My issue is: There is an online shop running on MySQL database, hosted somewehre on the internet. Now I'd like to do some administration stuff from my C# application.
What I want to do: All I want is to run SQL-queries on that database and get the results as entities in my application so I can browse through them like through normal Lists/Classes and then post back the changes to the database. The problem is not the connection to the database - it works fine (using SSH and Connector/NET driver) - but the question, how to turn the SQL-results into C# classes.
I had a closer look at Fluent NHibernate and SubSonic, but I still can't figure out which one suits best or - even worse - if these are really the right approaches to my problem.
So I don't want to build an application which stores its own data in a database but gets the data it needs from a public database.
I hope I could make myself more clear this time :)
Thanks in advance!
ORM is definitely the way to, because it allows you to abstract your data access.
You may find a code generator helpful (to avoid the repetitive task of writing the classes and all their properties): NHibernate Code Generation.
This way you can still use classic NHibernae instead of Fluent Hibernate, which by the way looks pretty useful.

Categories

Resources