I would like to access SQL server with F#
It doesn't seem like there is any way to generate models using the Entity Framework. I have seen some answers on S.O. but they appear to be quite generic. I would ideally like to select or update using strongly typed objects.
Ideas?
I recommend FSharp.Data.SqlClient. SqlCommandProvider allows you to write strongly-typed selects/updates.
Related
I'm trying to use mvc3. The online documentation says how to connect one class to one table. anybody have a suggestion on how to run stored procedures and return the results to a view?
MVC is not responsible for the way you access your data. There are many technologies that you can use including
Plain old ADO.NET
LINQ to SQL
NHibernate
Entity Framework
LINQ to SQL is probably the easiest way to get it working without any prior knowledge. Check out Scott Gu's post http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
I'm trying to get a UI using MVC. I'm currently battling with MVC3. There does’nt seem to be much documentation.
Here’s what I’m thinking. I believe I need to create stored procs for each query. I’m creating the the LINQ to SQL for the model. I’m trying to figure out how to create the cotroller. Any suggestion on how to input data to the stored proc and return results to the view? The default controller classes dont seem to do anything
Am I doing this right? Or MVC2/MVC1 the easier way to go?
I'm new to MVC on .NET. Thanks in advance.
There is plenty of documentation, if you look for it... Also, http://www.asp.net/mvc is a good place to start.
What it seems like you really need documentation for is LINQ-to-SQL, not MVC, which is here: http://msdn.microsoft.com/en-us/library/bb425822.aspx
There's also a great ScottGu tutorial here: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
The whole series is available here, including a PDF download: http://scottonwriting.net/sowblog/archive/2010/07/27/links-to-scott-guthrie-s-using-linq-to-sql-tutorials.aspx
I believe I need to create stored procs for each query.
You could do this but it might be an overkill. I would recommend you watching the tutorials here. Paragraph 5. covers tutorials about using Entity Framework for data access. Try them out and if you encounter some specific issues don't hesitate to ask a question by showing what you have tried and what didn't work for you.
If you're using Linq to SQL, you don't need to use Stored Procs at all.
If you want more information on MVC generally, try doing the NerdDinner example.
We run a series of reports every 6 months and store the results to tables that can be queried/viewed at any time in the future. Depending on the cycle either two or four tables will be added. They have a standard naming convention of yyyy_mmm_Table_x.
Our website is built using ASP.Net MVC2 and the database is modeled using EF4 using the standard model designer, not Code First.
I would like to be able to dynamically add the report tables to the EF4 context at runtime. I don't want to have to manually add them to the model using the designer, otherwise every reporting cycle we have to update and recompile the model just because we added the extra reports. That would be a maintenance headache when nothing else has changed.
I can get a list of the available tables simply by querying sysobjects. If I could get this list and add the tables to the context when the site started up then I could use something like the Dynamic LINQ library to query against them depending on which table the user selected from a dropdown.
I can't use EF4's Code First out of the box because that would force me to create concrete classes for the tables and that would just be the same maintenance headache. I suspect I could use the same strategies the Code First framework uses to dynamically update the context, but I haven't looked at this library at all and I'm hoping someone familiar with it can point me in the right direction.
Otherwise I think I would have to drop back to ADO.Net to handle this area. That may be the best and simple way so I guess I'm looking for comments. I'm not a zealot so I don't need everything to be in LINQ and EF4. :) But it would seem to be a little cleaner and consistent, especially if it allows me to make use of Dynamic LINQ. But sometimes the old way is just simpler.
So, if you have any suggestions or comments I would love to hear them.
Thanks!
Even with common EF you still need new data type for each table because when you map the table you need new ObjectSet of new entity type to be able to run queries. As I know it is not possible to map two tables to the same entity even if table structure is absolutely same.
All runtime mapping is stored in MetadataWorkspace prepared by EntityConnection. So if you want to play with it you can start there but public interfaces of these classes don't look promising.
I guess you want to run Linq-to-entities on these tables so using Stored procedure returning data from correct table based on data parameter is probably not an option.
You should use common ADO.NET for this.
I have the need for sql based library that will allow me to create products, order items, orders, etc to support e-commerce on a .net mvc site. Does anybody have a suggestion as to where I can purchase a library like this or should I write it myself?
Thanks,
Chris
This might help start you off if you're stuck with getting started with your database schema, it's a library of free database models:
Library of Free Data Models from DatabaseAnswers.org
There's even a sample Orders and Shipping model you could start off with.
I'd then suggest starting off with tool such as SubSonic or Linq to SQL to build your data access widgets:
SubSonic Project
I don't understand why you need a library for this. Since you are not using an open source shopping cart there must be some need for a custom solution. Therefore you should design the tables yourself based on the needs. You can then create Stored Procedures that you call from within your .net code to update the data within the tables. This is pretty trivial and I doubt you need a specific library to accomplish this.
I have an asp.net mvc application and i need to connecto to the DB i have saw a tutorial video that connect to DB using wizard by adding DB connection and determine the DB and add a model but i need to know if i can use connection string and query the DB or calling procedures in DB ???
I need any tutorials or step by step article that describe how to connect to DB without wizard and call procedures and query tables.
Thanks in advance and i am a begineer in MVC
I hesitate to respond to this, but EVERY video you have seen is likely using an OR/M to generate the Model and the DAL. The generated DAL will likely encapsulate your calls to the stored procedures that you're asking about.
The thing is -- and here's why you're not getting the answer you're looking for -- each OR/M is going to have a different method of retrieving data from and inserting data into the database. How you retrieve data from the DB using an OR/M is going to be different if you're using Entity Framework, Linq to SQL, SubSonic, NHibernate, or any other OR/M.
So, the question is to you. Are you using a OR/M? If so, which one? If not, then you will use the standard ADO.NET calls to retrieve and store data. This is also reflected in my comment to your original question.
Yes you can (google ado.net for tutorials on ado.net), but it's not the MVC way. The MVC way is to use some sort of ORM (Object-relational mapping) such as NHibernate, Subsonic or Linq for SQL.
how to connect to DB without wizard and call procedures and query tables.
To call a procedure (here it will return no result, just perform some action):
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection .Open();
using(SqlCommand command = connection.CreateCommand(nameofthestoredprocedure))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("#someparameter", somevalue);
maCommande.ExecuteNonQuery();
}
}
You can put your connection string in the config, just like you're used to.
You can call procedures the same way you would from any .Net application too. #svinto's advice about using an ORM is another way of doing things and is well worth looking at too. Many of the good examples for ASP.Net MVC use the ORM techniques.
If you don't want to go down that route, you might benefit from creating a seperate class library project that you reference from your MVC application. Your Class Library project can act as your data access layer (DAL) where you handle db calls, etc...
Your Controllers can then call your DAL and processing methods to populate entities for the Views.
Ahmy, I think the best advice to give would be before you start off developing using the MVC framework is to have a look into the principles behind the MVC pattern and domain driven design.
Specifically , have a look at repository patterns etc.
You can still add connection strings to your web.config in a block and access them as you would have done in a webforms project, after all Asp.net MVC is based on webforms. Its just likely that you wouldn't really want to do this if you're utilising MVC the way it was intended, its all about seperation of concerns.
www.asp.net has some great intro. examples worth watching.
Try downloading NerdDinner, or even better ... ContactManager iteration 1 (the tutorial directly answers your Q). Those should give you a good idea for how to handle database access. I wouldn't suggest looking at something like Oxite or MS StoreFront though, as these are a bit more complex.
To specifically answer your question: the connection string, like in ASP.NET, can go in your web.config or hard-coded in your application.