0

I am trying to map entity framework to oracle view using code first.Here is My Codes:

Hospital.cs Model

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Entities
{
    public class Hospital
    {   

        [Key]
        public string SBRS_KURUM_NO { get; set; }

        public string PAYDAS { get; set; }

        public string KURUM_ADI { get; set; }

        public int KURUM_KODU { get; set; }

        public string KURUM_ILI { get; set; }

        public string KURUM_ILCESI { get; set; }

        public string KURUM_TUR_ADI { get; set; }

        public string KURUM_TIPI { get; set; }

        public string IL_KODU { get; set; }

        public int ILCE_KODU { get; set; }

        public string AKTIF { get; set; }

        public string KURUM_TUR_KODU { get; set; }

        public DateTime GUNCELLEME_TARIHI { get; set; }

        public string BASAMAK { get; set; }

        public int YATAK_UNIT_SAYISI { get; set; }

        public string HASTANE_ROLU { get; set; }

        public int BAGLI_BIRIM { get; set; }

        public string KURUM_ROLU { get; set; }
    }
}

HospitalMap.cs Mapping Class

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Entities.Mappings
{

    public class HospitalMap : EntityTypeConfiguration<Hospital>
    {
        public HospitalMap()
        {
            this.HasKey(t => t.SBRS_KURUM_NO);

            this.Property(t => t.SBRS_KURUM_NO).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.ToTable("HOSPITALS");

            this.Property(t => t.SBRS_KURUM_NO).HasColumnName("SBRS_KURUM_NO");
            this.Property(t => t.PAYDAS).HasColumnName("PAYDAS");
            this.Property(t => t.KURUM_ADI).HasColumnName("KURUM_ADI");
            this.Property(t => t.KURUM_KODU).HasColumnName("KURUM_KODU");
            this.Property(t => t.KURUM_ILI).HasColumnName("KURUM_ILI");
            this.Property(t => t.KURUM_ILCESI).HasColumnName("KURUM_ILCESI");
            this.Property(t => t.KURUM_TUR_ADI).HasColumnName("KURUM_TUR_ADI");
            this.Property(t => t.KURUM_TIPI).HasColumnName("KURUM_TIPI");
            this.Property(t => t.IL_KODU).HasColumnName("IL_KODU");
            this.Property(t => t.ILCE_KODU).HasColumnName("ILCE_KODU");
            this.Property(t => t.AKTIF).HasColumnName("AKTIF");
            this.Property(t => t.KURUM_TUR_KODU).HasColumnName("KURUM_TUR_KODU");
            this.Property(t => t.GUNCELLEME_TARIHI).HasColumnName("GUNCELLEME_TARIHI");
            this.Property(t => t.BASAMAK).HasColumnName("BASAMAK");
            this.Property(t => t.YATAK_UNIT_SAYISI).HasColumnName("YATAK_UNIT_SAYISI");
            this.Property(t => t.HASTANE_ROLU).HasColumnName("HASTANE_ROLU");
            this.Property(t => t.BAGLI_BIRIM).HasColumnName("BAGLI_BIRIM");
            this.Property(t => t.KURUM_ROLU).HasColumnName("KURUM_ROLU");
        }
    }
}

My Context

using System.Configuration;
using Domain.Entities;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.EntityFramework;
using System.Collections.Specialized;
using Domain.Entities.Mappings;

namespace Domain.Data
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class SptsOracleDbContext : DbContext
    {
        public SptsOracleDbContext()
            : base(new OracleConnection(ConfigurationManager.ConnectionStrings["SptsOracleDbContext"].ConnectionString), true)
                    { 

                    } 

        public DbSet<BranchType> BranchTypes { get; set; }
        public DbSet<Branch> Branches { get; set; }
        public DbSet<StaffStatu> StaffStatus { get; set; }
        public DbSet<ManagerialTitle> ManagerialTitles { get; set; }
        public DbSet<AcademicTitle> AcademicTitles { get; set; }
        public DbSet<Hospital> Hospitals { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

        base.OnModelCreating(modelBuilder);
            modelBuilder.HasDefaultSchema("SPTS");
            modelBuilder.Ignore<Hospital>();
            modelBuilder.Configurations.Add(new HospitalMap());

        }
    }
}

When I try to use hospital model using context.Hospitals.Count() then it says this error:The entity type Hospital is not part of the model for the current context.

How I solve this issue?

Many Thanks For Helps

tcetin
  • 979
  • 1
  • 21
  • 48
  • Make sure your connection string is correct and I dont think you could pass the connection string to constructor just the name would be sufficient. also have a look at this http://stackoverflow.com/questions/20688922/the-entity-type-type-is-not-part-of-the-model-for-the-current-context – Zaki Apr 29 '16 at 08:13
  • There is no error about connection.I can migrate my models to oracle database.The error is about view mapping – tcetin Apr 29 '16 at 08:15

0 Answers0