I am looking at creating an application to record gym workout(set,reps, etc) and I was wondering what framework and database backend to use. I am currently thinking C# .Net 3.5 for the framework because I am familiar with it but I'm unsure about how to store the data. Originally I was thinking of xml files and parsing through them but that seems like more work then is needed. If I was to use SQL would I be able to run that from my own machine (Windows 7) and what would be the best method to connect? ODBC, LINQ etc.
Thanks in advance
Linq-to-SQL is a very easy to learn, easy to use and straightforward way to map database tables 1:1 onto domain objects in C#. You can install the free SQL Server Express editions on your machine locally, and use Linq-to-SQL against those.
It has a great set of features, visual designers, and using LINQ queries against SQL Server tables is really quite powerful to use and nice to write.
So unless you have any specific requirements (like supporting backends other than SQL Server or such), I would definitely recommend going with Linq-to-SQL first.
Tutorials:
Scott Guthrie has an outstanding blog post series on Linq-to-SQL and how to use it - highly recommended
The NerdDinner ASP.NET MVC demo app also contains Linq-to-SQL and you can learn a lot from it - great 100+ page intro tutorial as PDF or in HTML format
a bit more advanced: Hooked On LINQ has tons of articles, demos, how-to's and so forth - for LINQ in general and Linq-to-SQL specifically
I would use SQL Server 2008 R2 Express for the backend. It's free and powerful enough for most smaller apps.
Not quite there yet, but this looks like a great place for SQL CE 4.0. Check out ScottGu's post about it: http://weblogs.asp.net/scottgu/archive/2010/06/30/new-embedded-database-support-with-asp-net.aspx
Since it seems to be a small utility kind of application and the database wouldn't be very large I'd suggest to use the SqlCE database. It makes sense to have the database embedded in your app rather than have a server based database. That way you could easily just copy/share your app without having to bother about the database setup.
If you're willing and able to get away from Microsoft solutions. I would highly suggest taking a look at the Ruby on Rails framework as well. It's great for getting things up and running quickly.
Related
I'm building a C#/WPF job search tracking application to keep track of resumes submitted, interviews, followups, etc and am not sure of the best way to store the data. Where/how would YOU store the data? My first thought was XML to keep it simple, but it seems like I should "model" my data since there will be lots of related bits of information. Would SQLite be a better choice? Other recommendations?
Since I assume you want to query and update that data I would even suggest an ORM like Entity Framework - it's easy to get started and the basic stuff like querying and updating will be very straightforward if you have worked with LINQ before - saves you the hassle of writing your own SQL queries. This also will allow you to easily extend your model later on should you decide to do so.
Edit:
There are self-contained light-weight alternatives that would still allow you to use LINQ:
SQL Server Compact:
Microsoft SQL Server Compact is a free
SQL Server embedded database ideal for
building standalone and occasionally
connected applications for mobile
devices, desktops, and Web clients.
Here' an article that describes how to get LINQ to SQL to work on it. Apparently you can also use LINQ to Entities on it but there's quirks (such as design-time support) that you'll have to work around.
SQLLite:
SQLite is a software library that
implements a self-contained,
serverless, zero-configuration,
transactional SQL database engine.
SQLite is the most widely deployed SQL
database engine in the world.
There's a LINQ provider for it called DBLinq
As #Robert Harvey pointed out in his answer there's (almost) full support for EF since there's an ADO.NET provider for SQLLite:
Support for the ADO.NET 3.5 Entity
Framework
Supports nearly all the
entity framework functionality that
Sql Server supports, and passes 99% of
the tests in MS's EFQuerySamples demo
application.
Generally, you want to store the data from your application in a database. For WPF and C#, that database is usually SQL Server or SQL Server Express, because Visual Studio 2008 easily integrates with those.
Do not use XML for this. XML is not intended to be a large scale storage medium; the purpose of XML is to provide a common language for different computer systems to talk to each other.
SQL Server Express is usable on any Windows PC; you just need to deploy the redistributable, using a named instance. See also http://msdn.microsoft.com/en-us/library/dd981032(SQL.100).aspx. If it's a small application and you want to go simpler, you can use SQL Server Compact Edition, or SQLite with the ADO.NET provider.
(EDIT: I made it a community wiki as it is more suited to a collaborative format.)
There are a plethora of ways to access SQL Server and other databases from .NET. All have their pros and cons and it will never be a simple question of which is "best" - the answer will always be "it depends".
However, I am looking for a comparison at a high level of the different approaches and frameworks in the context of different levels of systems. For example, I would imagine that for a quick-and-dirty Web 2.0 application the answer would be very different from an in-house Enterprise-level CRUD application.
I am aware that there are numerous questions on Stack Overflow dealing with subsets of this question, but I think it would be useful to try to build a summary comparison. I will endeavour to update the question with corrections and clarifications as we go.
So far, this is my understanding at a high level - but I am sure it is wrong...
I am primarily focusing on the Microsoft approaches to keep this focused.
ADO.NET Entity Framework
Database agnostic
Good because it allows swapping backends in and out
Bad because it can hit performance and database vendors are not too happy about it
Seems to be MS's preferred route for the future
Complicated to learn (though, see 267357)
It is accessed through LINQ to Entities so provides ORM, thus allowing abstraction in your code
LINQ to SQL
Uncertain future (see Is LINQ to SQL truly dead?)
Easy to learn (?)
Only works with MS SQL Server
See also Pros and cons of LINQ
"Standard" ADO.NET
No ORM
No abstraction so you are back to "roll your own" and play with dynamically generated SQL
Direct access, allows potentially better performance
This ties in to the age-old debate of whether to focus on objects or relational data, to which the answer of course is "it depends on where the bulk of the work is" and since that is an unanswerable question hopefully we don't have to go in to that too much. IMHO, if your application is primarily manipulating large amounts of data, it does not make sense to abstract it too much into objects in the front-end code, you are better off using stored procedures and dynamic SQL to do as much of the work as possible on the back-end. Whereas, if you primarily have user interaction which causes database interaction at the level of tens or hundreds of rows then ORM makes complete sense. So, I guess my argument for good old-fashioned ADO.NET would be in the case where you manipulate and modify large datasets, in which case you will benefit from the direct access to the backend.
Another case, of course, is where you have to access a legacy database that is already guarded by stored procedures.
ASP.NET Data Source Controls
Are these something altogether different or just a layer over standard ADO.NET?
- Would you really use these if you had a DAL or if you implemented LINQ or Entities?
NHibernate
Seems to be a very powerful and powerful ORM?
Open source
Some other relevant links;
NHibernate or LINQ to SQL
Entity Framework vs LINQ to SQL
I think LINQ to SQL is good for projects targeted for SQL Server.
ADO.NET Entity Framework is better if we are targeting different databases. Currently I think a lot of providers are available for ADO.NET Entity Framework, Provider for PostgreSQL, MySQL, esql, Oracle and many other (check http://blogs.msdn.com/adonet/default.aspx).
I don't want to use standard ADO.NET anymore because it's a waste of time. I always go for ORM.
Having worked on 20+ different C#/ASP.NET projects I always end up using NHibernate. I often start with a completely different stack - ADO.NET, ActiveRecord, hand rolled wierdness. There are numerous reasons why NHibernate can work in a wide range of situations, but the absolutely stand out for me is the saving in time, especially when linked to code generation. You can change the datamodel, and the entities get rebuilt, but most/all the other code doesn't need to be changed.
MS does have a nasty habit of pushing technologies in this area that parallel existing open source, and then dropping them when they don't take off. Does anyone remember ObjectSpaces?
Added for new technologies:
With Microsoft Sql Server out for Linux in Beta right now, I think it's ok to not be database agnostic. The .Net Core Path and MS-SQL route allows you to run on Linux servers like Ubuntu entirely with no windows dependencies.
As such, imo, a very good flow is to not use a full ORM framework or data controls and leverage the power of SSDT Visual Studio Projects (Sql Server Data Tools) and a Micro ORM.
In Visual Studio you can create a Sql Server Project as a legit Visual Studio Project. Doing so allows you to create the entire database via table designers or raw query editing right inside visual studio.
Secondly, you get SSDT's Schema Compare tool which you can use to compare your database project to a live database in Microsoft Sql Server and update it. You can sync your Visual Studio Project with the server causing updates in your project to go out to the server. Or you can sync the server with your project causing your source code to update. Via this route you can easily pick up changes the DBA made in maintenance last night and push out your new development changes for a new feature easily with a simple tool.
Using that same tool you can compute the migration script without actually running it, if you need to pass that off to an operations department and submit a change order, it works for that flow to.
Now for writing code against you MS-SQL Database, I recommend PetaPoco.
Because PetaPoco works Perfectly inline with the above SSDT solution. PetaPoco comes with T4 text templates you can use to generate all your data entity classes, and it generates the bulk data layer classes for you.
The catch is, you have to write queries yourself, which isn't a bad thing.
So you end up with something like this:
var people = dbContext.Fetch<Person>("SELECT * FROM People where Username Like '%#0%'", "bob");
PetaPoco automatically handles parameterizing #0 for you, it also has the handy Sql class for building queries.
Furthermore, PetaPoco is an order of magnitude faster than EF6 and 8+ times faster than EF7.
So in total, this solution involves using SSDT for SCHEMA management, and PetaPoco for code integration at the gain of high maintainability, customization, and very good performance.
The only downfall to this approach, is that you're hard tieing yourself to Microsoft Sql Server. However, imo, Microsoft Sql Server is one of the best RDBM's out there.
It's got DBMail, Jobs, CLR object capabilities, and on and on. Plus the integration between Visual Studio and MS-SQL server is phenomenal and you don't get any of that if you choose a different RDBMS.
I must say that I never used NHibernate for the immense time that needed to start using... time wasted on the XML setup.
I recently did a web application in MVC2, where I did choose ADO Entities Framework and I use Linq all the time.
I must say, I was impressed with the speed! and our site was having around 35 000 unique visitors per day, in around 60Gb bandwidth per day (I reduced radically this 60Gb number by hosting all static files in Amazon S3 - Great .NET wrapper they have, I must say).
I will always go this way. It's easy to start (just add new data item, choose tables and that's it! for every change in the database we just need to refresh the model - made automatically in just 2 clicks) and it's fun to use - Linq rules!
With the economy the way it is my team and I have been looking into using MYSQL to reduce our licensing costs. I am wondering if there are any gotchas or issues that may crop up.
Is there anything we need ot do special to get .NET to talk to mysql as opposed to MsSQL?
When developing for it will LINQ to SQL have issues?
Any caveats we should be aware of?
Not a direct answer, but if you are familiar with SQL Server, then consider SQL Server Express (2005 or 2008). It is also free, and you'll be familiar with it, thus not requiring research into mySQL ;)
That said, check this out: http://dev.mysql.com/tech-resources/articles/dotnet/index.html
You'll need the MySQL Connector for .NET, if you don't already have it, in order to get your .NET application talking to MySQL.
Then you'll have access to MySqlConnection, MySqlCommand, MySqlDataReader objects etc.
LINQ to SQL is for SQL Server only, but there are third-party LINQ providers for MySQL - here's one that looks promising, although I haven't used it myself.
one big one is the support you can get when working with MYSQL if you dont pay the license.
Microsoft hasnt develop yet LINQ to MYSQL support, it maybe some projects out there but they are not guranteed
Here is a post which shows the matrices of the comparison. The database feature section is worth to look at.
http://swik.net/MySQL/MySQL+vs+MS+SQL+Server
Well, I say you're doing the right thing moving to MySQL. SQL Server's licensing cost is prohibitive and since MySQL does the job free and has no limitations like the Express edition I think using it as a backend is a solid idea.
I've used SQL Server express for more than a year now and what irks me most is that it under-uilizes the server's resources so you're not getting enough bang for the buck with express edition. If you have a website with plenty of data or one that gets plenty of visitors then you'll quickly outgrow SQL Server express, and then you'll find that you either have to somehow win a lottery to get the money for the full edition or re-write all your queries for a cheaper DB.
So better plan ahead, go with a cheap DB in the backend. MySQL is a very good choice.
You could just ignore the database being used an opt to use an ORM. That way you won't have to care what database you're using, and move between them (atleast in theory), effortlessly.
Try SQLite. I've used it and really enjoy it. There's even a free admin tool that has AutoComplete (wow). It's suitable for any site that has less than 100k page views per day. There are some downsides to be sure, but the light footprint and compatiblity with LINQ (via DBLinq, which is still in Alpha but I've used it just fine) make it a win in my book.
Be aware that the MyISAM engine doesn't support transactions, whereas InnoDB does.
I'm in the process of refactoring an application and I've decided to use a mobile/embedded database.
I've been reading about SQL Server Compact Edition, but I was wondering if any of you knew of any other databases that could be used and don't have huge download sizes, as my current application is about ~2MB (installer). SQLite would be nice, but AFAIK the GSoC implementation of LINQ-to-SQLite is rather buggy at the moment.
Thanks!
I have tried out db40 once (not the compact edition) - it is an object database. However, depending on your needs it may be a rather comfortable thing to use. They note that they support linq even for the compact edition:
http://www.db4o.com/s/compactframeworkdb.aspx
VistaDB and (as you mentioned) Sql Server Compact Edition are two small options for an embedded database. Sql Server Compact Edition can be used with Linq to SQL or Entity Framework. I believe VistaDB can be used with the Entity Framework.
Also, if you do not require a relational database, you may want to consider db4o. Rob Conery writes about this here.
Hope this helps!
I haven't used it myself, but you might want to look at BlackFish. I'm not sure about its Linq support though, but Delphi supports Linq so it may. Another may be Embedded Firebird - again, not sure about the Linq side of things.
I'm creating a small database application to teach myself the following concepts
C# programming
.Net 3.5 framework
WPF
LINQ ORM
I want to use Microsoft Access as the database but I can't seem to find any mention of whether its possible to use SQLMetal to generate the ORM code from a Microsoft Access database.
Does anyone know if this is possible?
If not, are there any small database or embedded databases I could use? I think SQL express would be overkill for me at this point.
For an embedded database, you can use SQL Server Compact Edition. Unlike SQL Server Express, it is not compatible with the LINQ to SQL designer, but it is fully compatible with the command-line SQLMetal. It has a few advantages over SQL Express, like to ability to use embedded or run from a file. Microsoft has a very handy chart outlining the differences between Express and Compact.
I don't think SQL Express would be overkill if you want to learn real-world skills - quite the opposite in fact! That'd be my choice, and whatever I chose, I'd stay clear of Access.
Good luck
AFAIK, Linq to SQL is MSSQL server provider specific. To be honest, SQL Express is pretty lightweight on todays machines.
BTW don't confuse LINQ with Linq to SQL. Linq is the underlying technology to provide "query" like support to .NET (amongst other things), where as L2S is effectively a Data Access technology built on top of Linq. Vanilla Linq will work with any ADO.NET provider, which of course Access is one.
Entity Framework will work with any compatible provider also but if SQLExpress is too heavy for you then I wouldn't recommend going down this path...
Thanks for all the responses. I never expected to get an answer this quick. For my test application I think SQL Server Compact Edition would be the way to go. I'm basically creating a money managment app similar to Microsoft Money and although it is an exercise to learn skills, I would eventually want to use it to manage my finances (provided its not too crap!)
This why I thought a fully blown database would be overkill.