I'm new to c # and asp.net/entity framework and in general to the concept of compiled language.
I wanted to know if, in asp.net, using the model and related functions to interact with the database, following a request the queries (which use variable values passed during the request) are generated at runtime or are they somehow precompiled together with the program itself?
What I would like to understand is if in an asp.net project using raw queries is still faster than using the model and therefore the or, in this case, nothing changes.
.net can make use of many libraries to connect to database. For example, you can use System.Data.SqlClient to connect to sql server database and run sql command against it. Entity framework is another library which can be used to connect to databases. This is a Object Relational Mapper (ORM) which generates queries dynamically, but you can also run sql statements against a database if you wish to using Entity Framework.
Related
I have a .NET Core 3.1 Web API project and I have an existing MS SQL database filled with data.
In my project I need to fetch the data from the database and to return it as results via the API endpoints. I already have the SQL queries for fetching the data in the format:
SELECT <fields>
FROM <table>
WHERE <condition>
And I wonder, what is the best way to get to fetch the data from the database and in the same time to be able to maximum reuse the SQL code that I already have.
I was considering options like:
using Entity Framework Core as a framework (but then, I already have the SQL code and I feel that using the entities with LINQ queries will only result with repetitive work, as I will have to translate my SQL queries into the LINQ queries);
using StoredProcedures and somehow call them (so that I can copy paste my SQL code inside of the procedures and on that way to maximum reuse them). Still I am not sure what is the best way to call / write stored procedures, do I need to use any framework;
using some combined approach, where I will actually use the StoredProcedures but I will call them via Entity Framework Core;
The above points were some conclusions based on my research, as I am not experiences with .NET Core development in general. So any advices will be helpful.
I would suggest having a look at Dapper. It's a Micro-ORM that easily enables you to query your database with SQL, and then mapping the result to .NET objects.
So I am using Neo4J and thought about how to update existing databases with schema changes e.g. a Node has new properties, edges changed, values changed, etc.
So far I was only using SQL Server and the Entity Framework includes a migration tool that can automatically write migrations when the schema changes.
How is this done in Neo4J?
E.g. a customer has v. 1.0 from our software and neo4j database. We make changes for v.1.1 and now we need to update the db from all our customers.
I am using Neo4J in C#. I have so far only found something similar for Ruby: https://neo4jrb.readthedocs.io/en/8.2.x/Migrations.html
You can use: https://www.liquigraph.org/.
Where you can create the cypher queries you need to migrate database data.
Since neo4j is basically "schema-less" (in the relational DB sense), there is no tool for migrating to a new neo4j "schema".
You will have to write code to update the DB.
I do actively maintain Neo4j-Migrations:
https://github.com/michael-simons/neo4j-migrations
It's basically an automated script runner, that stores schema versions inside the same database as a subgraph. It is also able to store them separately in a Neo4j server supporting multi databases.
As you mention that you are using C#: This tool is Java based, but I do also provide native binaries for all 3 major OSses availabe on GitHub. You might can integrate them into your workflow.
I have data stored in a MySQL database and I'm accessing it through entity framework 6. What I want to do is to extract the data and store it in a server-independent manner, so that I can use this data in the future for bootstraping of a larger database (where the data from MySQL is only a small portion of). The target database will not be MySQL.
The MySQL data was there before, so I used Database First. For the new database I use Code First. The MySQL data also needs some clean-ups, what is done in code. So the workflow is:
Read data from MySQL with Entity Framework database first
Optimize/enhance/correct it in code
Store in another database using code first
So my first thought was using SQLite, but sadly, Code First is not supported.
Using some other format (i.e. XML/DataSets/CSV) to store the data would require me to reimplement the import code.
Right now I didn't find another embedded database with Entity Framework support. As Entity Framework is meant for relational databases, I would say that Redis (or other NoSQL dbs) won't do the trick.
I also thought if "converting" H2 using IKVM.NET and then using H2 as SQLite replacement would be an option -- but there's the risk that this might fail due to some internal dependency not supported by IKVM.NET.
So I would be glad to get answers to the following questions:
Would the H2 way work? Is there even a stable/working ADO.NET provider?
I wouldn't care much about the local storage format (could also be JSON etc.) -- is there anything not-SQL, but providing Enitity Framework support?
Did I miss something? Is there a way I just didn't see yet?
Here are some related questions I stumbled upon which deal with the possibility of using Entity Framework to use files:
Entity Framework with text files (no database!)
A list of Entity Framework providers for various databases
Entity Framework with XML Files
Microsoft Entity Framework using a flat file as a data source
There is no complete solution, but there are many ready-made parts:
This project wraps the compiled Jar of H2 after IKVM.Net
with classes that implement the ADO.Net interface
to allow for easy use in .Net projects:
https://code.google.com/p/h2sharp/
EF provider for SharpHSQL (which doesn't work, because, SharpHSQL is too old, it's port of Hypersonic 1.4):
https://github.com/ArsenShnurkov/SharpHSQL/tree/master/src/SharpHsql.Linq
here is the description of build process:
https://groups.google.com/forum/#!topic/h2-database/QAvFqbyd4_0
https://code.google.com/p/h2sharp/wiki/BuildingH2Sharp
The authors of above code did a great job of writing such huge amount, so i think it's nothing wrong with writing some more to finish your task.
I've got an older ASP project that is being re-written into a responsive MVC4 w/bootstrap web application. The original version used direct SQL queries to interact with the application backend SQL database, and a custom class called EmployeeUserInfo that directly queries the ERP system for current employee information(current tasks, hours worked, etc). That connection is strictly read-only.
Using Entity Framework, it was extremely easy to create the models for the various writable databases that make up the application, but how can I add the original EmployeeUserInfo class to this EDMX model? I'd prefer not to rewrite the class because it does a lot of querying and analyzing to build the EmployeeUserInfo object. Is it possible to combine another class with an EF database-first generated model?
I'm stuck now because I can use the EmployeeUserInfo as the model for a view, but then I cannot access the EF generated model to read/write to the application database. I feel like I'm overlooking something here and making this more difficult than it needs to be.
My application currently uses ado.net to access the database.
It allows users to configure dashboards by passing custom sql. The custom sql includes joins on multiple tables and the columns of every table are included in the result.
We are migrating from ado.net to entity framework 4.
How do I execute the same queries using entity framework?
Also other code in the application requires firing custom complex join queries on the database. This is done by developers.
Yes you can use inline queries and even stored procedue in entityframework
see example for query http://msdn.microsoft.com/en-us/library/bb738451
see example for stored procedure http://msdn.microsoft.com/en-us/library/bb896334.aspx
If you have dynamic queries you cannot execute them through EF. EF works in strongly typed manner so it expects that you created the type with correct properties (with correct types) at design time (you can create the type at runtime as well but it requires you to create dynamic assembly, emit IL, etc.).
Use your old approach for this type of queries.