Unable to understand the Connectivity [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am learning C# and I want to access a database. I have been searching pages on .net database connectivity for the last two - three days. I also came to know that it has several ways for the connectivity and this is exactly where my mind started to ask a number of questions. Please tell me if I am wrong in my understanding.
Check out this Diagram 1.
Now what I am getting here are five ways of connectivity:
Linq to Objects
Linq to Datasets
Linq to SQL
Linq to Entities
Linq to XML
Here is another Diagram 2 of ADO.net Architecture -
I have read the definitions, but am not able to differentiate the functionality and purposes. Can anyone give me a short explanation of both diagrams for my understanding?
Suppose I am a programmer who write code in C#; which way should I
prefer to write desktop based has database connectivity that
has future?
To Software Developer is it needed to go through all the
preceding ways of data access from database?

For the answer to number 1, use Entity Framework and a database. The database could be relational (like SQL Server), or document-based (like MongoDb). If you just grab the free Visual Studio 2013 express and start by creating a new project from a template, you'll probably end up with some version of SQL Server to start out with.
You have a lot of options for Linq to Whatever because sometimes you just have to get data out of repository and if you can use Linq as a facade to it, then getting your data out is that much easier because it feels a lot like getting data out of a database. There's even Linq to Twitter. For a brand new project though, you'll most likely use a database.
For the answer to number 2, you would only do that on an existing application that you are maintaining. It is fine technology, but if you're creating a new project, use Entity Framework.

Under the covers of all the data libraries, every time you access the database three things happen:
- a connection is made to the database
- a command is created (to select, update, insert or delete data)
- the command is executed in the database
In the case of LINQ or EF, the SQL for the command is generated automatically from your objects, but ultimately, the same three actions happen.
If you want to understand the basics, start with the ADO.NET objects. If you want to get something running more quickly take a look at EF, or nHibernate.

Related

how can I save and load information in a desktop inventory application C#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Im developing this desktop app for study reasons
but im using SQL Server for database management so reading around the web i find some articles on this and why it is bad practice, i cannot move my entire project to another PC without installing SQL Server. then i find this:
Save and load inventory
So i don't know what method of saving and loading information I need for this project, I think in SQL Lite or maybe I can use a simple file to save all the information like the mentioned post.
Im using a DB with relationships and i dont know if i can made it with a data persistence file. What should I do? what is the best practice?
PD: Sorry for my bad english
Usually your SQL Server would be hosted on a remote computer when used outside development, but it depends on exactly what your application is supposed to do.
If it's a requirement for you to be able to switch computers, and not host your database on a remote server, I'd say using SQLite is a good choice.
Alternatively, you could have 1 big file that has all your data instead of a relational database, although I wouldn't really recommend it. It's good for quick prototyping of things, but all your data would be denormalized, which can end up being more effort to work with than SQL. This is what the inventory example you linked does.
If you are planing to move your application on different computers and don't want to install any database management system there then SQLite is the best option.
All of your data will be stored in one file and you can freely move your application an other PC without installing any database management system there.
Here is good article explaining that in which scenarios SQLite is good choice.

How does Entity Framework (v4 and up) perform for massive (1 million plus rows) queries? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am currently exploring of using Entity framework for the windows based (forms) application I'm developing that does data mining for a dataset of more than 1 million rows (my datasources are from oracle, sql server, sqlite). What the application will do is I parse these information to the users local client, and I utilize linq to objects in mining useful information. The said application shall only read information to the source database as its output is written in an excel file.
Given the significant ease of using the Entity Framework in terms of reducing the development time (this is the first time I will be using an ORM, and coding the necessary dataaccess objects takes about 80% of my time based on the previous projects I've done before), I would like to ask if it's worth it to use EntityFramework to the application I'm working in? How much would be the performance drop (as compared to using DataReaders) when reading tables for over 1 Million rows?
Also, given that I'm new to this technology, I would much appreciate it if you could refer me to useful tutorials and best practices.
Using pure ADO.NET will give you practically best performance you could get. But bear in mind that after you fetch data from data source, you would still need to map results to your object model (something that is done by EF automatically) so that you can perform actual data mining.
Mapping could be tough or easy process to do depending on how complex your data model is. For example, Entity Framework is good at mapping hierarchical data structures, which is useful when fetching related entities (or even their related entities) along with the actual entity.
You should also consider how often does your data model changes (and how big those changes are), so you calculate maintainability cost too. Having tons of SQL that you have to change every time you add new column is another point of getting problems. In this case, maintaining EF model with POCO's would be easier and more convenient.
Note that there are other O/RMs that can give you kind of best of two worlds (performance of DataReader and easy mapping to POCOs of Entity Framework). Among these are: NPoco (former PetaPoco), Dapper (the one used at StackOverflow), NHibernate (using HQL can be quite fast), OrmLite (has basic LINQ-like queries support) and many others.
Take a look at Dapper's performance benchmarks results that might give you some picture of what performance can be achieved with popular O/RMs.
Performance of either technology of fetching data is really dependent on what data model you have in the database.
That's why it's important not only to analyze existing benchmarks, but also perform your own based on your particular use cases on your data model. As a starting point, you can grab Dapper's performance tests code and tweak it according to your needs (data model, typical queries, etc), so that you get more comprehensive and realistic performance results using different frameworks.
EF is never as fast as using raw ADO.NET with an OracleCommand. After all, EF is another layer on top of ADO.NET; it's main goal is to provide programmers with convenience features of mapping raw columns into fields and rows into objects.
If you need the absolute top-notch performance, then you need to use raw ADO.NET. The downside of this is the fact that you need to start fiddling around with untyped rows and columns.
There ain't no free lunch - either you have top performance but an unpleasant programming API, or you get convenience and productivity - at a performance price.

.NET Entity Framework, clean way to implement it? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm currently learning LINQ especially SQL requests with the entity framework.
I used to write native SQL-queries before, and I've implemented it with one class in my projects called "SQL_Connection" or something.
So I had all my SQL-procedures stored in one class.
Now as I'm willed to learn the entity framework the right and cleanest way from beginning, I'm asking myself where do I put all those linq-procedures I create during a project.
Do expierienced people put them in the class-file of the related class, or are they using a big sql-class where all those procedures are stored in?
I'm asking myself where do I put all those linq-procedures I create during a project.
Where you create them.
If you are not totally ignorant on .NET you will have a TON of LINQ queries and only SOME will be EF related - the syntax is the same. You will use LINQ in your code to sum and aggregate in memory arrays, and do a lot of things.
The beauty of LINQ is that all changes to the underlying provider are isolated and / or checked by the compiler, so there is no need to have all in one place "in case I rename a table".
I keep the LINQ where I need it. This allows me to isolate layers without having a mother of all queries class. Especiall as some of the LINQ queries are multi step queries involving one or more data access then grouping and correlating in memory.
Seriously, the "one class to rule them all" (sql) is an artefact of the fact that SQL is a string, so in case of a database change you need to find all SQL that touches that changed element and that please without going through tons of code. This is absolutely not needed with LINQ.
That's up to your pleasure. Answering the question: do create BLL classes for your related set of objects. By this, a minor change won't make you itchy. Assume you added a new column to a table, having that table's (and other related ones') operations located easily is good, right? Avoid too big files. Try to stay modular and etc.
If you need a reading, check out this Wiki link about MVC architecture.

what is the best way to connect to database in c#? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a beginner in c# and i'm looking for the best way to connect to and work with sql server in c#. i found there are three ways to work with databases:
ADO.NET
Linq
Entity Framework
but i become confused as to which one is more useful and applied.
please help me?
thanks
I'm looking for best way to connect to and work with sql server in c#
'best way' can be treated differently depending on your project requirements. There is no best way for all cases. Some times you need ease of development, some times you need best performance, some times you need compromise of both (then I pick Dapper). Also it depends on complexity of your application - whether you have rich domain model, or you simply display table data on UI.
1.ADO.NET
Fastest way, but requires lot of manual coding. You should manually setup database connections, open and close them, create commands, provide parameters to commands and execute commands. Mapping of query results also should be done manually.
2.Linq
It's not way to connect to database. Linq is language integrated queries, which have many implementations - Linq to Xml, Linq to DataSet, Linq to Object, Linq to SQL, Linq to Entities etc.
3.Entity Framework
Entity Framework uses Linq to Entities and it is built on ADO.NET (internally Linq queries are are translated to ADO.NET code). It is easy to use, because EF handles connections, generate and execute commands, and map query results to entities for you. But you should pay with performance for that.
There is only ONE way to connect to a database . ADO.NET, more specifig: the Connection object.
Now, LINQ, ENtity Framework - guess what, they do not talk to the database. They use ADO.NET to do that.
They are all about easier programming in the application - talking to the database is done by the same underlying classes. Everything goes through a Connection, a Command and a SqlReader if data is returned.
That said, definitely learn Entity Framework - an ORM is baseline and writing handcrafted SL should be left to those instances it makes sense. Very complex queries that can not be expressed in an ORM form. And learn proper SQL - databases can do a LOT more than most people are aware of.
There is no "best way", because there are many advantages and disadvantages to each one of them, so it depends.
For example, entity framework is heavy, but convenient way to connect to database. It generates objects from your tables and views automatically.
LINQ is less heavy, but some people find it less convenient.

How to record and store data when using team foundation explorer? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a C# windows forms project with a friend and we are using TFS for our source control. The program we have written scrapes data off a couple of webpages at regular time intervals and this is updated to the UI.
However, we would like to be able to store this data for future reference. We will be gathering around 1000 bits of data every few seconds for several hours a day.
I'm relatively new to programming and know very little about databases and couldn't find anything on the internet about how to use them with team foundation server. What's the best way to store this data so it is accessible to both me and my colleague?
So far, we've used local XML files but as I say we need somewhere to centrally store the data.
Sorry if there's any information you need that I've missed off - this is the first question I've asked on a forum - but let me know and I'll provide any info I can.
I look forward to your help,
There is nothing specific about TFS that would keep you from using databases.
If you have installed Visual Studio as your IDE to work with TFS as your source control you probably have a copy of SQL Server Express installed. I would look into how to utilize that. You may want to look at Linq to SQL or ADO.Net to provide your connectivity to your database from your applcation. You will likely get a great deal more flexibility and performance depending on how much data you are collecting if you keep it there vs files.
ADO.Net Tutorial
Linq to SQL Tutorials
Entity Framework
Create a .txt file and every time the service runs append a new line to the text file.
How to add new line into txt file

Categories