So, I promised to see if I could help a friend with a small asp MVC application. I've started to regret it though since I haven't touched Entity Framework for many years.
We have a MSSQL database where users can post and list their own data (only). We don't want to have individual DB users, users logon using OAuth with external providers, which is working good.
Now we need to fix the CRUS and match the useridentity with his own posts. From our discussions there's three paths ahead.
Handling all the CRUD in webapp-code, a lot of examples and seem to work nice. My friend is kind of DB-centric though and an open database where someone suddenly could list all data using Crystal or Excel scares him.
Handling it in views, this is kind of a small webapp for now but I guess that could result in slow JOINS if there are a lot of posts in the end.
Handling all the CRUD with Stored Procedures, old style
I haven't used Entity Framework since it was brand new so I'm not aware of it's features today. Any advice or good resources on why to choose one over the other are welcome
Best Regards!
Related
I'm pretty new to Razor/MVC (and StackOverflow!), but I recently started a project at an internship and could use some advice. Basically, I am responsible for making web forms that users can fill out, and this info is stored in a queue table. Once approved by the DBA team, this data is inserted into several tables in the main DB. The good news is I already figured out most of this. However, the one thing I seem to be struggling with is the Active Directory.
I want this form to allow a user to enter search terms (last names or usernames), return a list of AD accounts, and then be able to select multiple accounts in order to grant various permissions.
I have a coworkers somewhat related code to use as reference, but it is just C# and not Razor/MVC. I believe I can learn from that code to connect to the AD, use PrincipalContext to bind the data, search it, etc. and return the info as a DataTable (note: still waiting on permission to access AD and make sure I'm using the correct LDAP path). But I am not sure how to implement this code. Should it all go in the controller? I thought all the data should be passed from the model? I know how to connect to, query, and update SQL Server databases in MVC. But that was easy--there are plenty of tutorials and VS can make the CRUD views, and so on. This is different, and I'm having trouble finding good resources that explain everything clearly.
This is alreadly longer than I envisioned...so basically I'm trying to find out:
-How/which part of the MVC should connect to the AD (model or controller? Both? How should those parts communicate?)
-How to actually pass this data to the View? (And as DataTable, DataView, WebGrid, etc.?)
Also: Using Visual Studio 2010 Ultimate, Razor/MVC3. I have some experience in Java, but to be perfectly honest I'm not great at programming (hopefully I can help change that over the course of this internship though!). I can try and post some of my code too, although that may have to wait until I get into work tomorrow. I hope this isn't too long or too general.. Thanks in advance for any help. It is greatly appreciated.
How/which part of the MVC should connect to the AD (model or
controller? Both? How should those parts communicate?)
Controller - in this part of MVC arch occur the Logic of your Application.
Only in the Controller happen the interaction between Active Directory.
The Model is the source of Object often retrieve and store model state in a database. To the controller, model is the reference of what object looks like in order to work with View.
To your next question you need a lot of examples and explanation to learned it.
Try to go here : http://www.asp.net/mvc/overview/getting-started
I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));
I have been trawling the internet for some months now, looking for some solid (and simple) examples regarding creating a new ASP.NET MVC3 (orMVC2) web site, that could connect to SQL Server 2008, using POCOs and EF4.
I understand the concepts, but seeing as their are many different ways to do the same job i'm struggling to find a full start to finish example I can use as a foundation, for a small web project I want to do in these technologies. I have the luxury of no existing db schema, but do not want to use code-first EF4 approach, I would rather do the model in SQL Server and then import entities into EF4.
I have created a project using 'the full stack' videos, but then realized that is specific to code-first, so sort of scratching my head again now.
If anyone has any good URL's to share, or indeed code/sln files then that would be great. Alternatively, if someone had the spare time to create such a project for a small fee, (50USD), from my specification then I would be interested in that also. I apologies if such requests are not permitted on this forum.
I look forward to hearing your comments.
This music store tutorial uses EF4. Although it's code-first, it shows how to connect to an existing DB as opposed to a lot of tutorials that create the DB "on the fly".
Here's a good example on how to "code first" with an existing database schema.
http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx
I have a pluggable system management tool. The architecture of this kind of thing is well understood (interfaces, publish/ subscribe, ....). How about the data store though. What do people do?
I need plugins to be able to add new entities, extend existing entities, establish new relationships, etc.
My thoughts (SQL), not necessarily well thought out
each plugin simply extends the schema when they are installed. In the old days changing the schema was a big no-no; now databases are very relaxed about this
plugins have their own tables. If 2 of them have an entity (say) person, then there are 2 tables p1_person and p2_person
plugins have their own database
invent some sort of flexible scheme where the tables are softly typed. Maybe many attributes packed into a single attribute. The ultimate is to have one big table called data, with key of table name & column name and a single data value.
Not SQL
object DB. I have no experience with these. Anybody care to pass on experience. db4o for example. Can I change the 'schema' of objects as the app evolves
NO-SQL
this is 'where its at' at the moment. Most of these seem to be aimed slightly differently than my needs. Anybody want to pass on experience with these
Apologies for the open ended question
My suggestion is go read about the entity framework
a lot of the situations you are describing can be solved (very elegantly) using table inheritance.
Your idea of one big table called data makes the hamsters in my computer cry ;)
The general trend is away from weakly typed schemas because they cannot be debugged at compile time. What you get from something like entity framework is a strongly typed extenislbe schema that you can code against using linq.
Object databases:
like you i havent played with them massivley - however the time when i was considering them was a time when there was no good ORM for .net and writing ado.net code was slowly killing me.
as for NO-SQL these are databases that meet a performance need. SQL performs badly in situations here there are lots of small writes occuring. I say badly tounge in cheek - it performs very well but when you scale to millions of concurrent users everything changes. My understanding of no sql is that it is a non rationalised format designed for lots of small fast writes and reads. The scale of sites that use these is usually very large.
OK - in response
I am currently lucky enough to be on a green field project so i am using EF to generate my schema.
On non greenfield projects I use sql scripts to update my table structures. As for implementing table inheritance in sql its very easy once you know the concept, its essentially a one to many relationship with a constraint that it will only ever be 0-1.
I wouldn't write .net code that updates the database structure ... that sounds like a disaster waiting to happen to me.
Beginning to think i have misunderstood what you are looking for. I find databases to be second nature as I have spent so long with them.
I haven't found a replacement for being meticulous about script management.
Im working on an application that needs to talk to a database. The application is written in C#. Im quite taken by LINQ and auto generating classes to represent the database and its tables, so first I considered using SQL as .NET only comes with support for LINQ to SQL. Right now Im leaning more to MySQL mainly because scaling the SQL server might get pricey and because the people within my company are more familiar with MySQL, including me. This is where dbLinq comes in. From what I have read dbLinq works fine for simple queries but might break down on more complicated ones. Could you share your experiences in using dbLinq? Should dbLinq still be regarded as experimental or could I expect to use it without a lot of problems?
Thanks, Bas
Edit:
I read that DbLinq is not able to handle more than one foreign key, can anyone comment on whether this is still the case?
I don't know much about dbsql but check out Entity Framework. It allows you do Linq and can be used with MySQL. Check out this SO question for more info on LinqToEntityFramework for MySQL Using MySQL with Entity Framework
I used EntityFramework to connect to MySQL db in my last project. It is gives some minor issues but reduces amount of effort required to code. I am super impressed with it. I had to do Paging and Filtering in that application. Because of EF this was a piece of cake.
This application had very less data (fraction of millions rows). I would like to know how Entity Framework will do in Applications which has large data.