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 13 posts 85 karma points
    1 week ago
    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 13 posts 85 karma points
    1 week ago
    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 678 posts 2399 karma points c-trib
    1 week ago
    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 13 posts 85 karma points
    1 week ago
    Manish Agrawal
    0

    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 139 posts 456 karma points
    1 week ago
    Marcio Goularte
    0

    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