Cannot access Data via Foreign Key in MVC5 Visual Studio 2017

  • Thread starter Thread starter Charlene1227
  • Start date Start date
C

Charlene1227

Guest
I am pretty new to the .NET Framework. When I am trying to navigate to the Revenue View in the UI, I will get the error ORA-00904:"Extent2"."Currency_Name":Invalid Identifier. It seems that I did something wrong in either my model or the context file, but I couldn't locate the issue. Any suggestion help! Thanks!


private Context db = new Context();


publicActionResult Revenue(int? id)

{
if (id ==null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var company = db.Companies.Include(c => c.Currency.ExRates)

.SingleOrDefault(x => x.Id == id);
return View(company);
}


My Currency model and ExRate model look like this:


namespace Project.Models
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

[Table("DATA.CURRENCY")]
publicpartialclassCurrency
{
[System.Diagnostics.CodeAnalysis.SuppressMessage

("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Currency()
{
Companies =newHashSet<Company>();
ExRates =newHashSet<ExRate>();
}

[Key]
[StringLength(26)]
[Column("CURRENCY")]
publicstring Name { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage

("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
publicvirtualICollection<Company> Companies { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage

("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
publicvirtualICollection<ExRate> ExRates { get; set; }
}
}



namespace Project.Models
{
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

[Table("DATA.EX_RATE")]
public partial class ExRate
{
[Key]
[Column("CURRENCY", Order = 0)]
[StringLength(26)]
public string CurrencyName { get; set; }

[Column("RATE")]
public decimal? Rate { get; set; }

[Key]
[Column("YEAR", Order = 1)]
[StringLength(4)]
public string Year { get; set; }

[Key]
[Column("QUARTER", Order = 2)]
[StringLength(2)]
public string Quarter { get; set; }
}
}



namespace Project.Models
{
using System.Data.Entity;
public partial class Context : DbContext
{public Context()


: base("name=Context")
{
Configuration.LazyLoadingEnabled =false;
}
publicvirtualDbSet<Company> Companies { get; set; }
publicvirtualDbSet<Currency> Currencies { get; set; }
publicvirtualDbSet<ExRate> ExRates { get; set; }

protectedoverridevoid OnModelCreating(DbModelBuilder modelBuilder)


{
modelBuilder.Entity<Company>()
.Property(e => e.Region)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.AccountName)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.Id);

modelBuilder.Entity<Company>()
.Property(e => e.Ticker)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.AccountOwner)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.TeamMember1)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.TeamMember2)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.FiscalYearEndIn)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.LocalCurrencyUnit)
.IsUnicode(false);

modelBuilder.Entity<Company>()
.Property(e => e.Group)
.IsUnicode(false);

modelBuilder.Entity<Currency>()
.Property(e => e.Name)
.IsUnicode(false);

modelBuilder.Entity<Currency>()
.HasMany(e => e.Companies)
.WithOptional(e => e.Currency)
.HasForeignKey(e => e.LocalCurrencyUnit);

modelBuilder.Entity<Currency>()
.HasMany(e => e.ExRates);


modelBuilder.Entity<ExRate>()
.Property(e => e.CurrencyName)
.IsUnicode(false);

modelBuilder.Entity<ExRate>()
.Property(e => e.Rate)
.HasPrecision(38, 4);

modelBuilder.Entity<ExRate>()
.Property(e => e.Year)
.IsUnicode(false);

modelBuilder.Entity<ExRate>()
.Property(e => e.Quarter)
.IsUnicode(false);

}

}

}


Continue reading...
 
Back
Top