Home

EF6.1.3 errors

edited January 2018
Hi

We have been using Linqpad for a while and we use it as an essential tool in our company. However, recently Linqpad has begun to spit out errors for queries that run just fine if run in a 'normal' .NET application.

One bug, for example, is that it ignores Ignore(...) statements in EntityTypeConfigurations, we have to add NotMapped attributes just for LinqPad to work.

Another one we can't solve at the moment (making it unusable for us right now) is this one:
"Invalid column name 'Patient_Id'.Invalid column name 'Patient_Id1'.Invalid column name 'Patient_Id2'"
We have normal setup on a class 'Prescription' with an entity type configuration.

// Prescription.cs public int PatientId { get; set; } public virtual Patient Patient { get; set; } // PrescriptionConfiguration.cs HasRequired(p => p.Patient) .WithMany(p => p.Prescriptions) .HasForeignKey(p => p.PatientId);

How can we fix this?

Thanks for the great tool, we are usually happy premium customers :)

luetm

PS: Linqpad 5.26.01, EF 6.1.3 with built in CodeFirst provider.

Comments

  • Are you able to reproduce this problem with a very simple database and new Visual Studio project?

    e.g.
    create table Patient
    (
    	ID int not null primary key,
    	Name varchar(30)
    )
    
    create table Prescription
    (
    	ID int not null primary key,
    	PatientID int null references Patient (ID),
    	Date datetime,
    	Description varchar(30)
    )
    
  • I'm sorry, I completely forgot about this issue. But it's still an issue. I'll try to reproduce it in a simple solution and will post back!
  • OK, so one bug that keeps creeping up is this one: https://github.com/luetm/LinqpadBug

    We have to use the [NotMapped] attribute everywhere, because Linqpad ignores the EntityTypeConfiguration (but they are loaded in the context, see TextContext.cs).

    Querying the Patients in Linqpad gives me:

    (6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties Patient.Gender in Set Patients.
    An Entity with Key (PK) will not round-trip when:
    Entity is type [CodeFirstNamespace.Patient]

    while when running the console app it works.

    I am so far unable to reproduce the bug mentioned in the first post. This is a big project and as I don't know what causes the issue it's hard for me to reproduce it. Where does LinqPad come up with those "Patient_Id", "Patient_Id1", "Patient_Id2" type columns? They don't exist anywhere in the database or the model... This could help me pinpoint the problem.

    Thanks you!
  • edited March 2018
    The problem is in your OnModelCreating method, in the following line of code:
    modelBuilder.Configurations.AddFromAssembly(GetType().Assembly);
    LINQPad subclasses your typed data context so that you can access its members without having to prefix them with "db.". This means that GetType().Assembly returns the LINQPad query assembly, not your typed datacontext assembly.

    Update it as follows:
     modelBuilder.Configurations.AddFromAssembly(typeof(TestContext).Assembly);
    
    and it should work.
Sign In or Register to comment.