This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is it possible to place a custom attribute on the Id of an entity using the designer? Would be useful for validation and form posting when using gui frameworks like ExtJs. Same goes for all the convention fields like LockVersion, UpdatedOn, etc. Cheers! Donovan |
|
|
This may seem like a stream of consciousness, but have you investigated the MVC RC1(Refresh!) release? The release notes are here: http://go.microsoft.com/fwlink/?LinkID=137661&clcid=0x409 Of particular interest is the support of IDataErrorInfo in the DefaultModelBinder which could mean piping in the Lightspeed validation errors to the ModelState property. This would save some plumbing code. One of the nice features of inheritance in Lightspeed is that a query to a base type will return the derived types cast as the base type. Unfortunately the MVC DefaultModelBinder does not seem to want to set properties which are unique to the derived type when using TryUpdateModel with the DefaultModelBinder. I think there is a gap here for your MVC sample to fill! A frustration I have is the fact that the Id on Entity is a setter only. This causes problems when deserialising some Json, when not using XmlSerializer or DataContractJsonSerialiser (I'm referring to Json.Net!) Would it not be a nice workflow to be able to hydrate an Entity instance with all it's properties (including ID, LockVersion, etc.) and allow it to be attached? I suppose it is the distinction between adding a new instance using UnitOfWork.Add(entity) for a newly created instance and UnitOfWork.Attach(entity) for an instance that has been remoted, had some changed made and come back. I am aware of the GeneratedId() method, but this does not play nicely with simple deserialization and binding scenarios. And there is no GeneratedLockVersion()! I know this verging on a request for POCO-ness, ie. a simple class with properties that can pass across boundaries and be seemlessly persisted. The great thing about Lightspeed is the conventions which saves writing lots of plumbing code. It's just that some of these conventions aren't playing well with the frameworks I'm using (MVC,ExtJs and Json.Net). I've looked at your DistributedUnitOfWork sample and it seems like a nice solution for WCF where you are able to put some C# code on the remote client server. But unless you write a JavascriptUnitOfWork which works in all the major browsers, it's not much use for the type of serialization that I'm working with! Keep up the good work! Lightspeed is a pleasure to use. It's saving me from the drudgery of XML with NHibernate and the hackery of trying to do Many-to-Many's in Linq To Sql! Watch out though, Fluent Nhibernate is on your tails! |
|
|
Hi Donovan, Funny you should mention this, as its something I have on my list to look at. Ill have a tinker with this today and see what we can come up with here. Previously I have gone for a custom model binder, but it would be nicer if it played well with the default, so I will see whats involved.. Will post an update later today :)
Jeremy |
|
|
Funny you should reply just as I send a feature request to Scott Guthrie! The TryUpdateModel methods in Controller.cs in the latest MVC uses the generic TModel rather than model.GetType() to work out which type to scan the properties of. This doesn't play nicely with UnitOfWork queries on a base type which return derived types cast as the base type The workaround is to register a custom binder as follows: public class EntityModelBinder:DefaultModelBinder { protected override PropertyDescriptorCollection GetModelProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) { bindingContext.ModelType = bindingContext.Model.GetType(); return base.GetModelProperties(controllerContext, bindingContext); } } It would be great if the LockVersion property could be dealt with in a custom EntityModelBinder too. Not sure where the code would sit. As part of OnPropertyValidating or SetProperty? OptimisticConcurrencyException messages should probably end up in ModelState. Looks like Lightspeed and MVC could be a great fit! Donovan |
|
|
Donovan, Thanks for the updates :) Looks like for now, the custom binder is really the only way of getting this to work as you require, so we might look to ship a small sample along these lines to demonstrate how its done assuming they dont patch this in ASP.NET MVC 1.0 :) We have been mulling a few other useful extensions which would help make life easier with LightSpeed and MVC, but yes, we think its got the makings of a great fit :)
Jeremy |
|