0

My problem is with my website using WebPages, Entity Framework 6.1.3, c#, and a SQL CE database. One of my "database-first "generated entity types is named exactly the same as the system.TimeZone class, but intellisense and the IDE are not correctly picking up/handling the name collision.

My question is how do I fully qualify an entity name in code (Using EF 6.1.3, Entity context) to prevent name collision with system classes.

I have a EF implementation of an existing db table. The table was named "TimeZones". The Entity model was generated using database first approach.

EF pluralization rules translated the table name to an entity named "TimeZone".

Problem is, when I try to new up my "TimeZone" entity, intellisense thinks I am trying to new up the "System.TimeZone" class because all dot references to my new up TimeZOne instance are to properties and methods of the System.TimeZone class. I had expected to see the properties of my entity model's TimeZOne entity.

I would expect to be able to fully qualify my TimeZone entity with a namespace or include my model's namespace in a using statement at the top of my code. However, the "namespace" that EF 6.1.3 Model properties provides me doesn't seem to be a true namespace. The EF was generated from an existing database.

RRRSR
  • 293
  • 1
  • 3
  • 12
  • It is as though intellisense merged the two class names into one and defaulted to returning the System class. Is this really how intellisense is expected to work when en entity class and a system class have the same name? Yes, I know, that is a programmer error and all programmers should know about all classes that are in corlib! – RRRSR Jun 05 '15 at 19:45

1 Answers1

0

Make your entity class path explicit when you declare an object of it:

MyApplication.Entities.TimeZone tz = new MyApplication.Entities.TimeZone();

or simply:

var tz = new MyApplication.Entities.TimeZone();

Your entity class should be preceded by something like this:

namespace MyApplication.Entities
{
    public class Person
    {
        //
    }
}
Alexandre Severino
  • 1,563
  • 1
  • 16
  • 38
  • Sorry to be so dumb, but where in my website in vs 2013 do I find "MyApplication". Intellisense yeilds no such animal. There is nothing on the solution properties or in the project(website) properties to give me any inkling where I can find the MyApplication qualifier – RRRSR Jun 05 '15 at 21:08
  • Further, my questin was how to "make your entity path more explicit". "Entities" is the name of my Entity context. I cannot find the hogher-level qualifier. – RRRSR Jun 05 '15 at 21:12
  • I edited it. Look for the `namespace` keyword for further qualifier information. – Alexandre Severino Jun 05 '15 at 21:43
  • It does not have such a construct. The entity classes were generated (that is what the database first option does). I would hate to have to continually insure that custom code STAYS added into generated code. – RRRSR Jun 05 '15 at 23:22
  • Here are the first 14 lines of the generated entity classes: //------------------------------------------------------------------------------ // // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // //------------------------------------------------------------------------------ using System; using System.Collections.Generic; public partial class Appointment { ... – RRRSR Jun 05 '15 at 23:31
  • No halp so far. None of the proposed "answers" seems to work. I can not find anything named "MyApplication". Nor is it feasible to put a namespace into the generated code for the entitiy classes. Nor can I seem to find the appropriate namespace to use when instantiating an entity object. Where do I find the namespace for the application in an ASP.Net website in Visual Studio? – RRRSR Jun 06 '15 at 19:44