Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

Entityframework Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01950: no privileges on tablespace 'USERS''

I used EF to connect to Oracle database and  I received the following error
Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01950: no privileges on tablespace 'USERS''
In my case the connection string has invalid value.
the user password was typed wrong.


EntityFramework Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01918: user 'dbo' does not exist'

While trying to use code first approach to connect to Oracle database using ASP NET C#.
I received the following exception
Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01918: user 'dbo' does not exist'
My current User Is IT_USER
The Reason for the error is that Oracle tried to create my tables which are in my first migration into dbo schema as SQL Server do, but in Oracle it is a User.

So you need to till Entity Framework where is my Table Should be
You have two solutions

First is to use DbModelBuilder.HasDefaultSchema
This will make all of your tables in this schema.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema("IT_USER"); 
    base.OnModelCreating(modelBuilder);
}

Second is to use System.ComponentModel.DataAnnotations.Schema.Table
This will give you the ability to change the schema when ever you want
[Table("STD_FA_VALIDATION", Schema ="IT_USER")] 
public class STD_FA_VALIDATION
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int SGBSTDN_PIDM { get; set; }
    public string NAT_CHANGE_IND { get; set; }
    public string WORK_IND { get; set; }
    public DateTime NAT_PROC_DATE { get; set; }
    public DateTime WORK_PROC_DATE { get; set; }
 }

Unable to create a constant value of type ‘’. Only primitive types or enumeration types are supported in this context.

the problem appears because you are using contains method in non primitive type
here is an example
Audit audit = new Audit();
List<int> ints = userReports.Select(y => y.ReportId).ToList();
List<ReportUserVisit> userReportLastMonthVisit = audit.GetAudit(userId, AuditType.Report)
                .Where(x => ints.Contains((int)x.ObjectId))
                .Select(x=> x.ObjectId)
                .GroupBy(x=>x.Value)
                .Select(x=>new ReportUserVisit { ReportId = x.Key, LastMonthVisitCount= x.Count() })
                .ToList();

note ints object, this will solve the problem.
because ints collection is list of int it can use contains method inside entity framework


filter attribute that checks whether current connection is secured

using APS.net Core to mark all website pages working with https protocol we will do this using IAuthorizationFilter. and here is an exampl...