Data Annotation .NET

Data Annotation .NET

ezdavisezdavis Posts: 20Questions: 2Answers: 0

Is there any data annotation for .NET?

I've worked through setting up a one to many file upload using an mjoin and models. Here is my main model where I have an issue -

public class ProductModel : EditorModel
    {
        public class Product : EditorModel
        {
            public int ProductID { get; set; }
            public string Identifier { get; set; }
            public string Title { get; set; }
        }
    }

When using the model like so

.Model<ProductModel>()

Everything pulls correctly but when I do an update I get the error "Cannot update identity column". I don't want to update this Product table, only my "link" and "image" tables. So from reading through the forum I found I need to use .set(false)

.Field(new Field("Product.ProductID").Set(false))
.Field(new Field("Product.Identifier").Set(false))
.Field(new Field("Product.Title").Set(false))

So, I added these fields and stopped using my model. Which solved my issue and allowed it to work as intended.

Do you have a way of using data annotation in my model? I would love to not have a add fields to each editor where I want to use this model and for any future scenarios that I come across. Would also be great to be able to set the format of the field this way. Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 54,897Questions: 1Answers: 8,605 Site admin
    Answer ✓

    The Editor models support a limited number of attributes, but not yet one for the get / set properties I'm afraid. They need to be specified via the Field class.

    That said, your suggestion is a natural extension of the attributes we provide already so I've added EditorGet(bool) and EditorSet(Field.SetType) attributes for the models. They will be in Editor 2.0.5 which I expect to drop next week.

    Regards,
    Allan

  • ezdavisezdavis Posts: 20Questions: 2Answers: 0

    I'm now using the EditorSet and it's working nicely. Is there also the ability to add SetFormatter and GetFormatter as annotations? Or is there a way to do this already when using a model?

  • ezdavisezdavis Posts: 20Questions: 2Answers: 0

    More specifically I want to use NullEmpty() to set my field to null instead of trying to insert a blank value which is causing my update to fail.

  • allanallan Posts: 54,897Questions: 1Answers: 8,605 Site admin

    Is there also the ability to add SetFormatter and GetFormatter as annotations?

    No sorry. At the moment formatters must be specified via the Field class.

    Regards,
    Allan

Sign In or Register to comment.