I need some advice on a little project im doing. I have a database which holds sales details, I have created a view which gets all the data that I need. I now need to get the data from the view manipulate the data and display it on the website.
please can you advice me on the best way i can get the data from the database to my asp.net application.
iv set up a datasource on the webpage, but im a bit stuck on how i can manipulate the data from this datasource.
UPDATE
sorry i forgot to mention that im using Interbase so im having to use a ODBC connector to interface between asp.net and the database. i was under the impression that LINQ2SQL is only for SQL server. normally i would just use data reader and put that into a dataset, but due to the interbase issue im having to create a SQL data source. – c11ada 1 min ago edit
You have different options:
Read data directly with DataReader or Dataset
Use Linq2SQL Use
Entity Framework (EF)
I would recommend using LINQ or EF because they are simpler and Object Oriented. Between them probably LINQ is simpler to set up and EF is more powerful.
It is easy to find info and examples of all those options.
That depends on the quantity of manipulation and your skills. Using datareader or dataset is normally have good knowledge then other techniques even though they are standard and good to use.
As #gustavogb suggested you can use anyone, but that really depends on your skills and interest to upgrade the knowledge.
Related
I have ben following through a tutorial that shows how to get started creating a Web Forms Application in ASP.NET...and have got to the part where you create Data Classes. These assume you are starting from scratch and generating the database from code - however - I already have a database created and populated from elsewhere.
Entering line by line to create the Class for each table seems very laborious. (I'm using VB.Net and VS 2013 by the way)
Q1. Can anyone help by suggesting a more automated way of doing this? Surely there is a tool to grab the schema?
Q2. Although the tutorial mentions Entity Framework and Code Behind briefly - having done some reading and research - I am very confused by all of the different terms for data access. Am I using ADO.NET ?? Is the methodology called Code Behind as opposed to something else? Are there better ways to connect to a database and Read/Update/Delete records.
Q3. If I want to use a Data Grid to show the data do I use the generated classes to do this - or just 'bind' the grid directly to the database?
I have been a developer for 40 years but the newer .Net models are causing me some confusion so any advice gratefully received. (and any simple books or tutorials that can be suggested would be helpful).
Thanks
Q1: What you want is to generate "EF Designer from database" by using a Entity Data Model.
In your project add a new item and look under "Data".
What this technique does is auto generating entity classes from your predefined database.
Q2: I suggest you read Getting started with Entity Framework. "Database First" is just a description of how you want to use the Entity framework - by saying you already have a database structure.
Q3: In this case if you use Entity Framework and the "database first" mechanism to generate entities you can databind the gridview from the result of a entity LINQ query, please see this example: Tutorial: Databinding
I'm using Entity Framework 5 with large database with 600+ tables (haven't counted stored procedure and views yet). After few start and running using Visual Studio 2012 I get Out of Memory error when trying to Update my Model.EDMX file (using right click Update from Database) or simply while trying to compile.
Quick google search says many people faced similar problem and someone in one forum suggested to use multiple EDMX files to avoid this.
(link http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/b4ce1494-a0b4-42c6-af56-4ecbfeb83e29)
My question is
1) Is there any way I can avoid this error and use large number of tables without trouble with EF?
2) Is Entity Framework model is right ORM for me for large enterprise database? If not, can someone suggest me good one?
Thanks in advance
To answer your first question.
I have found that updating the Entity Framework does not seem to work reliably in all cases.
Have you tried deleting all the objects in the model and inserting them again? It may be an acceptable workaround.
I'd recommend spending some time looking into nHibernate. It's not as user friendly in terms as UI than Entity Framework but that should be an advantage for you if you are dealing with a large number of tables.
http://nhforge.org/Default.aspx
Also, you're aware that you don't have to map all of the tables in your Entity model? You can just bring in the ones you need. I'm assuming that you don't need all 600 tables for what you're doing.
When is it appropriate to create a helper class for a sql server database using the asp.net framework? Basically I'm trying to create a minature wiki (with multiple pages) and storing all of the data/strings for a specific page into a table on it's own.
Always and Never.
Always, because you want good separation of your data tier from your business logic and presentation tiers (or model and view, or whatever framework you use). Make sure you're thinking of it in these terms, too.
Never, because this is already done for you, on several levels. There are numerous ORMs out there, including Linq-to-sql, NHibernate, Entity Framework, and more. More than that, what is ADO.Net but a set of classes to encapsulate your server?
Well it could be appropriate to return a single instance of a DbConnection object - that way you only specify how to connect to the DB in one spot.
You may find it useful to have a base class for your ADO layer which provides these generic methods to deal with the ADO (part of the .NET framework for connecting to SQL server).
You could have a helper method to populate an object from a DataReader using reflection too.
Also for putting parameters together to send to a SQL command or Stored procedure.
Hope you find this helpful. :)
It's heavily dependant on your project.
For code clarity, and your own sanity, you might find it easier to make a wrapper class for all of your Database manipulation. This way you can have the rest of your code work with native objects, rather than the contents of a DataReader.
Just my advice, but hopefully helpful.
I just started working on an asp.net / C#.net application that is going to call a number of different procedures. The -only- thing these procedures do is create database table views, and the only thing I want to do is to store the information in variables. Then pick out which columns I want to convert to JSON, and then make a JSON string. I've actually written code for that in C#.net already, which is smaller, but since I switched to asp.net mvc I'm a little unsure if I should keep it or go with the whole Linq thing.
I checked out the Linq --> SQL drag & drop functionality, and that instantly created about 200 lines of code with set & get methods and everything.
So my question is, is it still worth using Linq even for just extracting data? Eventually this data will be fed to a javascript timeline, which is where I was told MVC would be highly useful with regards to Ajax functionality.
Since you are only using LINQ-to-SQL for data retrieval, I can't think of a single reason NOT to fully utilize it. I've been working on an MVC 1.0 project since last April. During that time, I've had to quickly become familiar with a number of technologies, LINQ-to-SQL being one of them. Get comfortable with it, and also look at the repository pattern...you will be very content and things will go relatively smoothly.
Now, when you get to INSERTs and UPDATEs, things are going to get a little more sticky. LINQ-to-SQL is still up to the job, but you'll need to understand how things work internally a little better. I highly recommend "Pro LINQ (Language Integrated Query) in C# 2008" by Joseph C. Rattz, Jr. The sections covering LINQ-to-SQL easily take up over a third of the book with detailed examples.
As far as the JSON objects go, LINQ-to-SQL's biggest contribution is that it allowed me not to have to worry about creating specialized views or stored procedures just to handle those one-off-types of data retrievals. My current project has a database of 65 tables...NO stored procedures. I can do filters, unions, multi-level joins...and it's all maintained in the application. Sweet...
Yes, it's totally worth it!
LINQ2SQL provides you a great subsurface to retrieve and save data to.
However, you'll need to implement your own Repository Pattern as you dig deeper into ASP.NET MVC.
And during the implementation of the Repository and the required (and even custom / webapp-state based) Queries, you'll be very glad to have all the power available at your fingertips that LINQ provides.
LINQ only adds to the available toolkit you can lean on when creating code. Even if you are using LINQ in a trivial way now, implement it, get familiar with it, and take advantage of the power it gives you both on this project and future projects.
Linq2Sql is quiet good for creating select queries. As it is appearing that you need to create JSON objects from database views it will be quiet useful
It is very simple to retrieve data from a database and display it inside a DataGrid. However, what are the current practices to push the changes in the DataGrid back to the database? One can achieve this by inserting a lot of meta information, however, it is very tedious and not reusable.
There are libraries for persisting data across tiers, but as you say it isn't a simple task. LiveCycle DS ships with this capability when used in conjunction with Hibernate on the server. GraniteDS and Tide can perform a similar function, but for the most part you are left rolling your own. If you are using one of the many MVC frameworks available (I use PureMVC) it isn't difficult to create this type of functionality. Kind of tedious, but not difficult.
Which server side technology would you be using? You need to use HttpServer, WebService or RemoteObject's in Flex to push data to this server side app and that would then update the database.
Unless of course we're talking about a Flex/AIR Desktop App where connecting to databases directly is possible.
You can use RemoteObject, if you have a Java class on the server side that takes care of database connection and provides method to update database.
Just Create an ArrayCollection object from modified datagrid and pass it while doing a method call.
I think making changes to the database is the easiest part of this whole thing. The hardest part is making the DataGrid know exactly from which database table each cell comes from. If you're the one writing the query, then you can probably return a lot of meta-data, such as the private key and table name for each cell.