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
    0

    Create Nullable field with PetaPoco Model

    Hi,

    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.

    Thanks

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

    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 792 posts 2970 karma points MVP 3x c-trib
    Aug 11, 2017 @ 07:41
    David Brendel
    0

    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.

    Alter.Table(yourTable).AddColumn("TotalNumber").AsInt32().Nullable();
    

    Maybe this works.

    Regards David

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

    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.

    Thanks

  • Marcio Goularte 374 posts 1346 karma points
    Aug 11, 2017 @ 14:48
    Marcio Goularte
    8

    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:

Draft