D
D
Dmitry2016-02-22 16:50:44
ASP.NET
Dmitry, 2016-02-22 16:50:44

What are the best practices for database access in C#?

Guys, tell me what Best practice to use to organize access to the database? Is it better to use Model First, create POCO objects based on the database, and then use Code First?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2016-02-22
@Nipheris

1) https://habrahabr.ru/company/microsoft/blog/101121/
Well, i.e. It seems clear what to use in new projects.
2) use the repository: codereview.stackexchange.com/questions/57401/repos... , but I ask you, do not make methods that accept Expression and return IQueryable - such a "repository" is completely unnecessary and does not abstract anything, but only harms . Make methods for each specific query type that accept specific search constraints and return an IEnumerable. It is realistic to test such methods, and you will not get a leaky abstraction that will suddenly give you errors at runtime for non-standard entity fetch requests. And most importantly - you will not depend on a specific ORM.
3) do not forget that ADO.NET and other ORMs have not gone anywhere, thick ones like NHibernate, and not so much. If you make two insert requests to the database in your application (some kind of telemetry service), there is no need to fence the garden with ORM. Or if you have an old-school database with a large number of stored procedures on the server, then a thick ORM is also useless (some kind of billing, for example).
If I remember anything else, I'll write.

A
andea23, 2016-02-24
@andea23

>What is better to use Model First, create POCO objects based on the database, and then use Code First?
you after all understand, what it will depend on specific tasks?
professorweb.ru/my/entity-framework/6/level1
metanit.com/sharp/adonet
https://geekbrains.ru/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question