After following the steps for mapping an existing table to a model, I realized the table had some dependencies.
For the last three times that helped, I just droped the whole DBContext and started again.
I would like to just update my context for accommodate another table, which relates to the current ones.
My current context is:
public partial class CompanyContext : DbContext
{
public CompanyContext() : base("name=CompanyContext")
{
}
public virtual DbSet<company> companies { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<company>()
.Property(e => e.name)
.IsUnicode(false);
modelBuilder.Entity<company>()
.Property(e => e.symbol)
.IsUnicode(false);
modelBuilder.Entity<company>()
.Property(e => e.address)
.IsUnicode(false);
modelBuilder.Entity<company>()
.Property(e => e.zipcode)
.IsFixedLength()
.IsUnicode(false);
modelBuilder.Entity<company>()
.Property(e => e.cnpj)
.IsFixedLength()
.IsUnicode(false);
}
}
A company's record has id_city which is not even appearing in the DbContext. But it is there in the model:
[Table("company")]
public partial class company
{
public int id { get; set; }
[Required]
[StringLength(70)]
public string name { get; set; }
[StringLength(10)]
public string symbol { get; set; }
[StringLength(80)]
public string address { get; set; }
[StringLength(8)]
public string zipcode { get; set; }
public int id_city { get; set; }
public int id_segment { get; set; }
[StringLength(14)]
public string cnpj { get; set; }
[Column(TypeName = "date")]
public DateTime? open_date { get; set; }
}
I would like to add the table cities to this context, what should I do? Is there any wizard for helping it?
I thought it could be just add something like:
public virtual DbSet<city> cities { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<city>()
.Property(e => e.name)
.IsUnicode(false);
}
but it doesn't work.