Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

IAudited and CreatorUserID type #2976


User avatar
0
edvin created

Hi,

we are building new ASP.NET zero applicacion arround existing database.

When mapping Entity.CreatorUserID (long) to SQL.CreatorID (int) we got mapping error.

So, is it possible to change IAudited to use int against long ?

Thanks for advance.

Edvin


12 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can do it like this:

    modelBuilder.Entity<YourEntity>().Property(p => p.CreatorUserId).HasColumnType("int");
    
  • User Avatar
    0
    edvin created

    Hi.

    I tried this already. I still got exception:

    Unhandled Exception: System.Data.Entity.Core.MappingException: Schema specified is not valid. Errors:
    (17,12) : error 2019: Member Mapping specified is not valid. 
    The type 'Edm.Int64[Nullable=True,DefaultValue=]' of member 'CreatorUserId' in type 'Sebit.Core.EF.Drzava' 
    is not compatible with 'SqlServer.int[Nullable=True,DefaultValue=]' of member 'ReferentID' in type 'CodeFirstDatabaseSchema.Drzava'.
    

    Somehow, it is also logical. We cannot save in64 into in32. Right ?

    If we have generic IAudited like IAudited<int> this could be solved.

    Thanks for any suggestion.

    Edvin

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You are right. In this case it is better to change database field's type, because it is hard coded in ABP.

    Even if you change CreatorUserID to int, then you need to change User's Id field and all other related fields.

    Thanks.

  • User Avatar
    0
    edvin created

    Yes i noticed that.

    I hope you will give me some magic solution. :D

    Why did you decide to use bigint for users and related references. bigint takes 8 bytes . This is loss of DB space.

    Each audited entity have 2 fields (creaded, modified).

    I believe int (2, xxx,xxx,xxx+) should be enought for all users.

    Edvin

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Using long was a decision at the very beginning of the framework and it became hard to change it in the future :).

  • User Avatar
    0
    edvin created

    Ok. I understant.

    Thanks. Edvin

  • User Avatar
    0
    fguo created

    I have an opposite scenario. I have my own entity "MyUser", which has an "Id" property corresponding to MySQL data type BIGINT(20). "MyUser" class inherent Abp.Domain.Entities.Entity. By convention, I don't need to declare the "Id" in my entity class, but I wonder what type the Abp.Domain.Entities.Entity.Id uses, int32 or int64? in another word, if the "Id" value in MySQL is over int32, does it cause problem? If so, how do I prevent it?

    Thanks,

  • User Avatar
    0
    alper created
    Support Team

    default is int32 but you can make it long like this MyEntity<long>

  • User Avatar
    0
    fguo created

    Do you mean to make entity class like this:

    public class MyEntity : Entity<long>{}
    

    It gives out compile error. I can only use :Entity<int> or :Entity.

    Can you give me a code example where to put <long>?

    thanks,

  • User Avatar
    0
    alper created
    Support Team

    you can see the samples: (these are real entities in Asp.Net Zero)

    [Table("AppFriendships")]
        public class Friendship : Entity<long>, IHasCreationTime, IMayHaveTenant
        {
            public long UserId { get; set; }
    
            public int? TenantId { get; set; }
    
            public long FriendUserId { get; set; }
    
            //.....
    }
    
    [Table("AppSubscriptionPayments")]
        [MultiTenancySide(MultiTenancySides.Host)]
        public class SubscriptionPayment : FullAuditedEntity<long>
        {
            public SubscriptionPaymentGatewayType Gateway { get; set; }
    
            //.....
    }
    
  • User Avatar
    0
    fguo created

    Not sure what I missed. When use the MyEntity in

    IRepository<MyEntity>
    

    , I get compile error: cannot convert to "Abp.Domain.Entities.IEntity<int>".

  • User Avatar
    0
    BobIngham created

    @fguo - the best way to get a complete example of how this works is to generate an entity using the RAD tool and select your primary key type. it will generate all of the code you need to work with long of Guid. Simply mimic the code generated in your own code.