I am creating my very first larger ASP.NET MVC application. After thinking about the application architecture for some time, I thought I would hear some other opinions.
I am using LINQ-SQL for my data layer. However, I am not planning on using the LINQ objects throughout the application, since I would like some more specific data types for some fields (ex I would like Url fields to be of System.Uri type, not System.String). It also seems that pasing LINQ objects around is not a very good idea since the DataContext may not always be available. I would absolutely like some comments on this.
I have created some more specific objects to represent my data. The LINQ objects can be parsed to these objects, and I have created some DataClient classes that utilize the LINQ DataContext to retrieve data which is then parsed to my custom objects and returned. This allows for using LINQ-SQL as the data layer only.
Now one complication comes to mind. How to update object values in the database. I am still debating whether to use my custom objects (thus requiring relevant properties to have setters) as argument for an update method. If I take this approach I am planning on making the Id : int property a nullable type, and only have the ability to set the Id property when LINQ data objects are parsed to custom objects. I think this makes sense, since the database is the only place identifiers are actually assigned.
This approach will not let me update records without first retrieving them from the database, even though I know the Id. On the other hand I could make update methods that will take every field as a parameter. However, this seems to be a lot of double code.
Now for the MVC model. I am not sure whether to use my custom objects directly in the views, or whether to create yet another representation of the same object for use in the ViewModel. Initially I thought it would be nice to use the same object, but then questions started appearing. What if the view requires other features of the model (ie. What if I want the view to render something controlled by the controller, but not dependent on the data-model. How would the controller tell the view what to do?)? Also, I would very much like to use the DisplayName and validation attributes available from the DataAnnotations namespace. If I want to localize this data, where would I put the resources (the custom data objects will not be in the same assembly as the website) Also, I would like to be able to use the objects in other (not web)applications?
I am looking very much forward to hearing your comments.