Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Manish Agrawal 25 posts 218 karma points
    Aug 10, 2017 @ 07:32
    Manish Agrawal

    Create Nullable field with PetaPoco Model


    I am using petapoco to create custom table in database.

    Now I want to change int and datetime property as NULLABLE. so I have set (?) with property datatype.

    public int? TotalNumber { get; set; }

    I have deleted the tables and running the project. It is creating new table with not Nullable field.

    Please suggest what I am missing.


  • Manish Agrawal 25 posts 218 karma points
    Aug 11, 2017 @ 05:19
    Manish Agrawal

    It will be good if any one can reply on it.

    when I am trying to create table with nullable fields it is creating not nullable fields in tables.

    Please suggest what is the approach to make this in petapoco. I have done this many times in MVC entity framwork but this is not working here.

    Regards Manish

  • David Brendel 719 posts 2652 karma points c-trib
    Aug 11, 2017 @ 07:41
    David Brendel

    Hi Manish,

    don't think this is possible with PetaPoco when creating the table with the poco. You could try creating the schema by sql. At least I now that with that you could set a field to nullable.


    Maybe this works.

    Regards David

  • Manish Agrawal 25 posts 218 karma points
    Aug 11, 2017 @ 12:29
    Manish Agrawal

    Thanks David for reply.

    but this will not help in my problem.

    I will wait Peta poco new versions if they fix this problem in new versions.


  • Marcio Goularte 244 posts 795 karma points
    Aug 11, 2017 @ 14:48
    Marcio Goularte

    Add this attribute: [NullSetting(NullSetting = NullSettings.Null)]

    [NullSetting(NullSetting = NullSettings.Null)]
    public int? TotalNumber { get; set; }

    UPDATE: Does it work with DateTime, I use it in a project.

    [NullSetting(NullSetting = NullSettings.Null)]
    public DateTime? Suporte { get; set; }
Please Sign in or register to post replies

Write your reply to: