I am new to .NET and have heard about several different ways of querying a SQL Server databse such as ADO.NET and the entity framework.
Can anyone give me some advise about the best way to go for new applications?
Thanks for any help or suggestions.
Database Connectivity using C/C++ This IDE is specially designed for C and C++ and easy to use. SQLAPI++ is a C++ library (basically a set of header files) for accessing multiple SQL databases (Oracle, SQL Server, DB2, Sybase, Informix, InterBase, SQLBase, MySQL, PostgreSQL, SQLite, SQL Anywhere and ODBC).
You can code SQL statements in a C or C++ program wherever you can use executable statements. Each SQL statement in a C or C++ program must begin with EXEC SQL and end with a semicolon (;). The EXEC and SQL keywords must appear on one line, but the remainder of the statement can appear on subsequent lines.
To connect to the Database Engine from another computer On a second computer that contains the SQL Server client tools, log in with an account authorized to connect to SQL Server, and open Management Studio. In the Connect to Server dialog box, confirm Database Engine in the Server type box.
To connect to a database instanceRight-click the SQL Server node in SQL Server Object Explorer and select Add SQL Server. In the Connect to Server dialog box, enter the Server name of the server instance you want to connect to, your credentials, and click Connect.
Here is an example using EF with code generation from the database (for a real app you probably want to generate your DB from the code, instead):
You will see a file MyEntities.edmx added to your project. You can open it in design view to see a diagram of your entities and relationships. Note that each entity should have a primary key - the easiest way to do this is to add an ID - auto increment field to each table, or a GUID column. Anyway now you can query your db like this:
// assuming a "Product" table, which has an entity pluralized to "Products"
MyEntities db = new MyEntities();
var cheapProducts = db.Products.Where(p => p.Price > 30); // var is IEnumerable<Product>
Entity Framework is the easiest, and its built in.
All you have to do is important your model, and then just update simple classes, that are automatically mapped to your db.
Its just like updating normal objects, but at the end you call SaveChanges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With