Base solution for your next web application
Open Closed

New database Object #2044


User avatar
0
zaktecs created

Hi,

I would like to add my table (Classes) to the dbContext eg. Student(Id,Name), Teacher(Id,Name) but don't seem to see where to do it. Does it go in the "EntityFramework Project|"

Do you have link on documentation on how to add new database object to extend this starter park.?

Many thanks

Zak


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

    Hi,

    There must be a DbContext class in your EntityFramework project under EntityFramework folder. You need to add your class to your DbContext.

  • User Avatar
    0
    gpcaretti created

    Some code:

    This is your new entity (place it somewhere in YourProject.Core project):

    [Table("ReBid")]
        public class Bid : FullAuditedEntity<long> {
    
            public Bid() {
                CreationTime = Clock.Now;
            }
    
            [DataType(DataType.Currency)]
            [Column(TypeName = "money")]
            [Range(0, double.MaxValue)]
            public decimal Amount { get; set; }
    
            public long RegistrationId { get; set; }
    
            [ForeignKey("RegistrationId")]
            public virtual BidderRegistration Registration { get; set; }
    
            /// <summary>True if this is the winning bid of an auction</summary>
            public bool IsWinner { get; set; }
        }
    

    Then add the proper IDbSet in the DbContext class you find in YourProject.EntityFramework project:

    public class YourProjectDbContext : AbpZeroDbContext<Tenant, Role, User> {
            ...
            public virtual IDbSet<Bid> Bids { get; set; }
            ...
        }
    
  • User Avatar
    0
    zaktecs created

    Many thanks gpcaretti. I will give it a try