I'm doing some statistical stuff for a university and I've got a question. I've got a starter background in C++ and read up on some C# and since I have access to the entire MS suite I think I'll go ahead and use the .NET framework. My question is, I would like to make my database searchable online. I'll fancy it up with some jQuery but for the most part, all I'll need is permissions to view or write and all of the queries one might like to run. My question: is there a specific method that would be more expedient for developing this? The MVC framework or something else?
For SQL Server, I think LinqToSQL provides the quickest, most convenient direct access to your data from C#. Start with a Linq data context, and then you can manipulate records in your database via strongly typed C# objects.
Related
Can i use a dynamic C# object to access database values. For example if i have a table name Settings, with different values could i simply call from code Settings.SomeSetting, rather then programming them all.
You could also use a C# ORM in order to do something like what you are trying to do.
Dapper.Net - A simple C# ORM.
NHibernate - A mature ORM which has been around while.
I don't have experience with either but both sound like something you are trying to achieve.
Here's a blog post showing one technique using a dynamic wrapper for ADO.NET data access. This should work against a query run against an Access database (as well as any other ADO.NET data source).
Yes, you can.
Probably you will get insane later, but you can. Also, if you want to access the data in a reflective way and without compilation check, you could just use DataSets. They suck, but... You are about to reinvent the weel.
Have a look at Simple.Data. It sounds like what you're looking for.
I'm trying to build a web application that let the administrator talk to the database through C# and add new tables and columns to fit his requirements (sort of a very simple database studio) but I'm not trying to just create some spaghetti application.
So I'm trying to figure out how to let those things dynamically (automatically) when he creates a table and use the table to build them :
1- The business objects or entities (the classes, it's objects and properties).
2- The Data access layer (some simple methods that connects to the database and add, update, delete retrieve items (objects)).
Is this possible ? any pointers on how to achieve it ?
EDIT
just opened your link!! .. it's talking about the data bound controls and stuff! .. my question is way more advanced than that!.
when you build an N-Layered application you start with the database schema and implementation and it's easy to do programtically then you start building the DAL classes which (add, edit, etc in other words the CRUD operations) in and form this database
what I want to do is to allow the web administrator to choose add the new table through my application and then -dynamically- the application would take the tables names and columns as parameters and create new classes and define within them the CRUD methods that will implement the SQL CRUD operations
then it would also create dynamically the classes and define within them the variables, properties and methods to call and use the DAL methods .. all this based on the table, column names
NOTE : All this happens on the run-time!
You might want to look into ASP.Net Dynamic Data. It's a RAD tool which very easily gives you CRUD functionality for your entities and more. Check it out.
Sometime back I had also asked similar question on SO. I got only one reply.
Today I was digging some information on MSDN and as I had guessed it, MS CRM entity model works based on metadata. So basically whatever a CRM developer is working against is just metadata, they are not real objects as such. Following is the MSDN link.
Extend MS CRM Metadata and here is the MS CRM 4.0 SDK.
I hope this should get you started.
Update: Recently hit upon Visual Studio LightSwitch. I think this is what we wanted to build. A UI which will pick up table information from DB and then create all CRUD screens. VS LightSwitch is in its Beta1 and has quite a lot of potential. Should be a nice starting point.
First, any man trying to create MS Access is doomed to recreate MS Access. Badly.
You are better off using ASP.NET Dynamic Data (as suggested) or ASP.NET MVC Scaffolding. But runtime-generated playforms that actually make decent applications are really pipe dreams. You will need developer time to do anything complex. Or well.
What you are asking is non-sense. Why? Because the idea behind BLL and n-tier is that you know your data model well, and can create a static class model to represent your data model.
If your data model is dynamic, and changing, then you cannot create a static BLL (which is what a BLL is). What you will have to do dynamically build your queries at run-time. This is not something that any of the traditional methods are designed to handle, so you must do everything yourself.
While it's possible to dynamically generate classes at run-time, this is probably not the approach you want to take, because even if you manage to make your BLL adapt to your dynamic database.. the code that calls the BLL will not know anything about it, thus it will never get called.
This is not a problem you will solve overnight, or by copying any existing solution. You will have to design it from scratch, using low level ADO calls rather than relying on ORM's or any automation.
I need to write a specialized, embedded database for some .net Apps. The database part itself is no problem (as said, it's specialized), but the access to it from my .net code is.
I was thinking of using LINQ as the only data access (so no ADO.net, which is fine for the scenario), but I've never done that and I wonder what I actually need to implement?
Do I need IQueryable? Is there a set of Standard methods/Interfaces I need to implement? Is there a standard for writing data or do I need to create my own semantics for it?
Do I need IQueryable?
Yes, this is where LINQ hooks up.
Is there a standard for writing data
or do I need to create my own
semantics for it?
Your own. OTOH that is normally the easier part - you normally dout do a JOIN or something when you update a row.
I personally use BLToolkit quite often these days (need something fast and leightweight). They have a SqlQuery object that can manipualte classes to tables. GOod enough for most direct db manipulation (and I dont use change tracking - most of my objets never change but are versioned in the database).
LINQ providers are quite complicated. As is writing an execution engine. Sure you want to go that way?
Writing your own linq provider is very difficult - I looked into it a while back and got discouraged... may still do it though.
See the answers here - a couple of tutorials are linked to.
I'm writing a .NET application and the thought of implementing a data layer from scratch is icky to me. (By data layer I'm referring to the code that talks to the database, not the layer which abstracts the database access into domain objects [sometimes called the data access layer and used interchangeably with data layer].)
I'd like to find an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works. I'll be talking to SQL Server only.
It doesn't matter to me if the library is in C# or VB.NET and I don't care if it's LINQ or ADO.NET. As long as it works.
** I want to emphasize that I'm not looking for data access technologies or mechanisms (e.g. LINQ, ORM tools, etc.) but rather existing libraries.)
If you are talking to only SQL Server the Linq to SQL is your best option. It is pretty easy to get up and running. You will get both the Data Layer and the Abstraction. All you have to do is provide a connection string to Linq to SQL and it will handle the rest.
If you are going to connect to other database than SQL you would want to with NHibernate.
NHibernate takes a little more work than Linq to SQL to get up and running. MS provided in Visual Studio a nice tool that can get you reading from a SQL database pretty quick.
Honestly as much of a fan as I've always been with NHibernate. With the latest release of Enterprise Library 5 Data Access Block that they added in the dynamic mapping support natively. I would have to strongly consider not using NHibernate on a project and instead use a forward database generation tool from my domain objects to create my database (perhaps even use NHibernate solely for the scheme export) or something like CodeSmith and use EntLib.
You can use easyobjects has a very small learning curve, and is very extensible.
From their web:
EasyObjects.NET is a powerful data-access architecture for the .NET Framework. When used in combination with code generation, you can create, from scratch, a complete data layer for your application in minutes.
I'd like to find an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works. I'll be talking to SQL Server only.
Might want to check out Subsonic. Though I personally find it quite limited, it's certainly not an ORM, but a "query tool." It will make CRUD operations easy and straightforward, and it generates partial POCO classes for every table in your database, rather than trying to map from a database to a domain layer.
Microsoft's Entity Framework might be what you are looking for to releave you from writing "the code that talks to the database".
The best things are that it already ships with Visual Studio and - depending on your requirements - you can use most functionality out-of-the box or manually adjust it to your custom business logic via T4 templates.
You can use it for forward and reverse engeneering and being a microsoft technology it integrates well with other MS products like SQL server.
I started using it 3 months ago in my current project at work which is composed of several windows and WCF services to convert third party data into our own database scheme. From the experiences we made with it, we'll be using the EF in future project a lot more.
What would you expect this framework to do with your exceptions? If it can't connect to your database, what should it do - crash the application, show an error message (winforms or WPF or ASP)... the questions are endless.
An ORM such as those suggested elsewhere in these answers is likely to be the closest you're going to get. Expecting a third party framework to provide all your exception handling isn't realistic - how would a third party know how your application is supposed to behave?
The direct answer to your question asking for "an existing generic data layer implementation which provides standard crud functionality, error handling, connection management - the works" is simple: use ADO.NET. The answers everyone else have provided actually go beyond that functionality, but your responses suggest that you think that there's something even further beyond - something that implements your data layer for you. My suggestion is that what you're looking for probably doesn't exist.
I am totaly new to SubSonic, and have never used any other tool like it.
I am not sure if SubSonic would be the right tool, or if there are any other tool that could help. Maybe someone can clarify things for me. :)
The scenario is this:
I have a c# application that fetches data from a set of secured web services, secured through WSE 3.0. The web services expose product data, press releases related to products etc.
The data is deserialized upon retrieval, so the result is a for example a 'Product' object.
Now I want to save this data. There are dozens of different classes that needs to be saved to separate tables.
I started out creating tables and data access logic manually but then I realized maybe this was something that a tool like SubSonic or NHibernate could help with?
Could any of them use the schemas from the web services to create the data access layer and data tables?
If so, how and where would I start?
As I said, I have never used any tool like this before, so I am not sure this is something they could be useful for.
Greateful for any feedback!
your question is not very specific, so i just can say what i'd gonna do. I am not so familiar with SubSonic so i'd prefer NHibernate. It's free and OpenSource. Of course it can help you in this situation, even though you would have to create the mapping by yourself. I assume you already have the classes you want to save, then you could simply annotate them with some NHibernate attributes and then, if not already exists hibernate would be able to create the database for you.
Another benfit would be the use of 'cascade' wich enables you to simply save a product entity and all its attached press releases (or whatever your structure is) would be saved too automatically, though i'd admit that you should use this features with care. NHibernate has a very active community and there are a lot of good example projects and tutorials. Simply use the search for some hints. To Start look on nhibernate.info and for usefull tips and best practices Ayendes Homepage
Hibernate is very powerfull but also complex and it takes some time to get used to all features it provides, but simple CRUD operations are very easy to accomplish. So if you really just want to save/load/delete this data and thats all you wouldn't have to learn HQL or touch the Criteria API.
Hope this helps.