1

I'm a very beginner in .NET and now I'm developing a little project (web API) using NancyFX framework. In my project, I need to use SQL database for some very basic tasks like storing registered users' details or getting some user information. I'd like to know what is the most popular, convenient and modern way of using SQL in .NET for beginners? I mean, should I use LINQ or just pure SQLClient functionality or are there any good libraries for working with SQL on .NET? I've tried to implement LINQ to SQL pattern but ended up with huge chunks of unused auto generated code and even bigger mess in my head...

1
  • 2
    Take a look at the entity frame work code first. Commented Nov 8, 2015 at 16:59

1 Answer 1

4

For a framework to communicate with you're database I would recommend using Entity framework, its very convenient and easy and has the Code first approach which you should read about. More over i suggest you follow the repository pattern,

https://msdn.microsoft.com/en-us/library/ff649690.aspx

This basically means - each object you save in the db, will have a repository which will contain all the object of its kind and that will be you're entry point to reading/inserting/updatibg/and deleting rows from the db, while abstracting away all details of implementation - in our case I recommend entity framework as I mentioned before.

Good luck

Sign up to request clarification or add additional context in comments.

2 Comments

I've read a little bit about the Repository pattern. If I understand it right, this approach is already implemented by the Entity Framework Code First. I think DbContext is basically a repository's base class. I have to derive from it and create my own class that will work on objects that represent my SQL database's tables. Am I right? Or do I have to put all the logic of communicating with the databse to separate classes for each entity (table)? I.e., if I have two tables: Clients and Friends, do I have to create a class for each where I put the CRUD logic?
Hey I am glad you read about it, the dbcontext object represents you're database, like you said you need to derive from it and than specify the DbSet's you need, in you're case - DbSet<Client> and DbSet<Friend>. You should put the CRUD logic inside a repository class dedicated to each entity in you're dbcontext, I recommend you read this article -tugberkugurlu.com/archive/… , which explains and demonstrates the repository pattern in work with entity framework, good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.