ASP.NET MVC Forum Application - asp.net-mvc

I need to write a forum application for a friend's web site. I want to write it in C# 3.0 against the ASP.NET MVC framework, with SQL Server database.
So, I've two questions:
Should I use Linq to SQL or the Entity Framework as a database abstraction?
Should I use the ASP.NET Membership API or add Users table and implement it myself?
Thanks.

There are lots of examples around internet which is using ling with ASP.NET MVC. But may be you can add your list NHibernate. If you do not want to add i suggest Entity Framework. Using ORM's is a plus.
I always chose write my own membership management layer. If you are a person like (write your own code and be happy when you are making changes in future.) write your own membership layer. If you are looking for a quick solution ASP.NET Membership API is a good choice.

Entity Framework definitely -- see below.
ASP.net Membership API -- easy to maintain.
Reason:
Entity Framework vs LINQ to SQL

1) How about both? Just create an abstraction and you could just use either. My recommendation is to use the repository pattern.
2) The membership provider has its strengths and weaknesses. For some projects, it was far too complex for my needs. However, it is great if you need to get something running in a short amount of time.

I won't answer the first question since i'm a fan of nhibernate
for the second question adding a users table and implement membership yourself i don't think you will be able to do it at least the right way (lot of people tried to make their own membership api but they messed up !)

1) Totally depends on how complex things are going to get. If you want a quick DAL that more or less mirrors your tables in a 1:1 fashion, go for L2S (or SubSonic if you want something more mature and supported). If you are going for more of an n-tier type thing where your tables and domain model are completely different, go for an OR/M like Entity Framework (or NHibernate if you want something that is pretty much better in every way)
2) ASP.net Membership is extremely complex, and there are bits of it that are fairly poorly engineered. However, it depends on how much experience you have with these things. If you enough to know how to take steps to avoid session fixation attacks, just roll your own because chances are it will be better then the canned solution. If you have no idea what that is, take the time to learn the default one.

Something to think about, SubSonic 3 is a pretty powerful data access generation tool. From what I understand, it basically wraps Linq to Sql inside of some very useful wrappers and makes using Linq a little more intutive. You can have a pretty powerful application built up in no time flat when using SubSonic. One little issue though, if you're using a shared hosting (say GoDaddy) you'll run into a medium trust issue. In that case you can always fall back to Linq To Sql without making many changes to your code base.
As for Aspnet_Membership. Just for the amount of tools it provides, I'd reccomend using it.
Good luck, and hope this helps.

Related

Concerns about ASP.NET SPA(Single Page Application)

Here is my knowing about ASP.NET SPA:
have to use Upshot to talk to the server;
have to use DbDataController to provide Web APIs;
have to use Entity Framework Code first...
so, many concerns come out:
have to provide metadata for the upshot to work, this will obviously expose the structure of your database;
can i use Entity Framework Database First instead of Code First? You may ask why. Because Code First don't provide you the ability to customize your database(index customization, stored procedure...etc.);
A problem i met: when i add a "TestUpshot.edmx" file(generated from database 'northwind') to the MySpaApp.Models folder(trying to test whether i can use the edmx classes in the MyDbDataController class, and generate proper metadata in the client side), and run the application, there is an exception:"System.ArgumentException: Could not find the conceptual model type for MySpaApp.Models.Categories."...
Need help here, thanks in advance.
Dean
I may be missing something, but there is no requirement to use any of the technologies you've listed.
An SPA is just a pattern. You can use whatever you need to achieve that. There may be benefits with choosing certain technologies, ie templates, tutorials, etc.
Doesn't really answer your question, but should lead you to experiment with what you've got.
SPA is actually a way to conceptualize your client application. SPA comes the closest to the fat client - data server concept from the current web approaches. Definitely this will be the ruling concept within a couple of years.
Your concerns can be addressed using JayData at http://jaydata.codeplex.com that provides advanced, high level data access for JavaScript against any kind of EntityFramework back-ends (db, model or code first). Check out this video that presents the whole cycle from importing your EDMX from SQL (this could eighter be model first definition as well) to inserting a new product item in the Products table from JavaScript.

Is Sharp Architecture good enough to use with ASP.NET MVC 3?

I'm trying to use Sharp Architecture to develop ASP.NET MVC 3 app.
But I found few issues:
SharpArch Edit controller takes NHibernate domain object and calls IsValid and copies data to NHibernate object fetched from Repository.
Why SharpArch uses direct propery assignment (TransferFormValuesTo functions) instead of session.Merge or session.SaveOrUpdateCopy?
Is it realy gool idea to fill domain object with form data and validate it, instead of using custom data annotation Validate attributes?
May be Sharp Architecture was cool in time of ASP.NET MVC, but is it usefull for now?
Well, lets say SharpArch is just another little but very opinionated layer over ASP.NET MVC. So, to reprase you - those "issues" are not issues; they are just opinions incorporated into SharpArch framework. Is it "good with MVC" or "bad with MVC" desicion should be up to developer. So "yes" for one, "no" for another.
The issue is with how you look at opinions. You never ever have to take them as something "all-for-all-situations-ever". You may have one project done and working like a charm with SharpArch inside but also have another one where SharpArch is just not the tech to use.
Another part about all of that is how you accept the opinion. Or not :) Decide if you feel comfortable with that or not. If you feel somethings wrong then try to decide on alternative or decide whether its worth writing something your own that would do the same thing as SharpArch but in a different way.
After all, SharpArch isn't big enough, its small and simple and easy to learn (which is also useful when writing your own alternative). But you have to decide whether to accept the opinion or not.
If you are talking about small to mid size systems then SharpArch and NHibernate could be too heavy..
Have you ever checked Nido Framework. It is simple but flexible framework develop following a simpler but solid architecture. You can develop your system on Nido and integrate that with MVC of ASP.NET front end.

usefulness of microsoft data access application

I am planning to start learning asp.net mvc. And also I want to learn Microsoft's Data Access application block. But I dont want to waste time in MDAC block if theres a better option to go for, or if MVC provides any good feature than MDAC. As I have heard MVC architecture automatically generates code.
So, please guide me regarding this. Thanks in advance.
It's not part of MVC per se, but I'd recommend using LINQ to SQL or LINQ to Entities (Entity Framework) over the Data Access application block if you're interested in a pure MS object relational mapping. You could also look at nHibernate or a variety of other ORMs to accomplish this. Any of these would suffice as the basis for the M(odel) in an MVC application.
Try the Nerddinner example application, there is also the data access included. The tutorials are extensive: http://www.asp.net/mvc/learn/
Don't work with MDAC block if you are not forced to! Try NHibernate, Entity-Framework or LINQ instead.

Which data framework is better for an ASP.NET MVC site - LINQ to SQL or NHibernate

We're about to embark on some ASP.NET MVC development and have been using our own entity framework for years. However we need to support more than our entity framework is capable of and so I'd like to get some opinions about using MVC with a more robust framework. We have narrowed down or choices to either NHibernate (with the Fluent APIs) or LINQ to SQL.
Which framework lends itself best to MVC style development (I know SO uses LINQ to SQL)?
If we want to support SQL Server, Oracle, MySQL - does that exclude LINQ to SQL?
As someone who has just switched from LINQ to SQL to (Fluent) NHibernate, here are a few things I've noticed.
LINQ to SQL took so long to figure out how to do the equivalent of a join-subclass. After many modifications, I read somewhere that it is not possible. It can only map inheritance if ALL the columns are in that same table. This is great if there are a few columns, but there are tons in my case and sub classes are parents to other sub classes and so on. Why should I put them all in one table for the sake of my ORM?
NHibernate from experience has been robust (sometimes too much for small quick projects) and although familiar with it through small projects, I felt it might be too much and went the route of LINQ to SQL since I could generate a DBML file and be going within minutes.
Fluent NHibernate. Takes the best of both worlds (in my case). I can map the way I want to and have my database the way I want and not have to compromise in my domain or data models. Also one word: Automapping... icing on the cake.
I would have had to go with another ORM once I found limitations and hit a few road bumps with LINQ to SQL, but Fluent NHibernate made this choice easy, and I don't think I'll leave it unless something comes around that does the job even better.
So, like Rob Scott said, the question is how are you abstracting you domain => data model? And are you starting with a domain or a database? How complex are the relationships? If you have any inheritance at all I'd say just go with a richer ORM framework and save yourself the grief.
Fluent NHibernate has some of the best documentation I've ever found and there are so much support, notes, blogs and resources it's self-hate to do anything less... IMO! I was up and running in less than 24 hours.
Oh and if your'e new to NHibernate pick up the NHibernate in Action book to help grease the wheels although there is a lot of help for that framework as well.
The best indication that a tool isn't working is when you have to WORK the tool... LINQ to SQL I was customizing, reading white papers, all sorts of madness and it refused to generate appropriate queries, right when I was tempted to modify my table and domain, I said let me give Fluent a whirl, and I'm happy I did.
Good luck to you.. Sorry for the long response; this has all been in the past five or so days, so I guess I'm still caught up :-)
I've had great success using Fluent NHibernate and dependency injection (Ninject, in my case) with MVC.
It seems to me though that any mature ORM should work well with MVC. Since the nature of MVC (Model/View/Controller) separates the three concerns, any ORM should fit quite nicely into the "Model" role.
LINQ to SQL is for SQL Server. Entity Framework supports some other databases as well.
NHibernate is good choice. You may use Castle ActiveRecord (it's built on top of NH) if you are doing data based application or Sharp Architecture for project guidance.
Entity Framework integrates nicely with MVC and supports other databases.
The short (and not so helpful) answer is that both of the ORMs you've mentioned will work with MVC. A longer answer is that you should think about how you want to work with your model objects. For example, do you want to do domain object first development (ala a Domain Driven Design approach), or are you implementing a "forms over data" type application where you might want to generate a data access layer from an existing db? What is your preference for specifying mappings? Do you want to use a fluent interface or are you happy with mapping files (or attributes on your domain objects)?
These are the type of questions you need to investigate when choosing an ORM -- and they're mostly independent of whether you're using MVC or Winforms.
Entity Framework makes things complex. Use Fluent NHibernate, with Repository pattern and inversion of control in controllers.
NHibernate will make lots of things easier. We have recently migrated from Entity Framework to Fluent Nhibernate, and Fluent NHibernate is definitely the better candidate.

ASP.NET MVC + ORM

I am in the start up of a project using ASP.NET MVC and have started creating my models. Since I know some Ruby On Rails and would like to use a system as similar to Rails Active Record as possible.
Have anyone used Castle Projects Active Record in a ASP.NET MVC application (or any application that is relevant) and have some experience to share?
Are MVC and Castle Active Record the right way to go or do you suggest I use LinqToSql instead.
Please share any thoughts and experiences you might have gain.
Edit: To clarify; I come from a long ASP.NET and C# background but have looked a little at Rails and love how easy you can create the ORM
I have used Castle Active Record with ASP.NET MVC. I highly encourage this model, as ActiveRecord/NHibernate are much more mature that LINQ to SQL or the Entity Framework.
I think that ASP.NET MVC has a bright future and would recommend it over Monorail for new projects. However, as I said, ActiveRecord is (in my view) a superior ORM to LinqToSQL.
Coming from a Rails background, Castle Project AR will feel closer to what you're used to, but Linq to SQL is better integrated with the whole Microsoft ecosystem and you may find this is worth the extra effort to learn it.
Linq to SQL has some major missing pieces, notable many to many relationships. If you're going the "pure" Microsoft route look at .net 3.5 sp1 and Linq to Entities, which uses the new ADO.net Entity Framework.
I've used the Castle ActiveRecord with MonoRail and it is fairly easy to use and intuitive, although the innevitable problems you'll come across are often hard to diagnose. Its documentation is also not the best (as with many open source projects). By default it uses NHibernate ORM underneath, and if you were specifically after using an ORM framework I believe there has been some effort to support LINQ with NHibernate, no idea how far it is along though.
I think it also depends on the size of the application, if its a quick project that won't necessarily be maintained heavily then the ease-of-use ActiveRecord gives might be handy, but then LINQ also seems pretty easy and neat. If it was a larger application I would consider rolling your own data layer using NHibernate, again if its specifically the ORM you want.
Do you need the ORM to be free (as in beer)/open source?
If you don't then I would highly recommend eXpress Persistent Objects from DevExpress.
If not, then I dont think LINQ is similar, I haven't used ActiveRecord from Castle but I guess that's the most similar to RoR
MVC doesn't know what ORM you are using, or is there even some ORM tool behind. Controller/Action must send object references to View, so that object can be simple int, string array, DataSet, Linq object, ActiveRecord object, whatever, it doesn't matter for View how some object is filled with data!
Prefer NHibernate as your persistence layer.

Resources