Coder Social home page Coder Social logo

Comments (5)

bilal-fazlani avatar bilal-fazlani commented on July 17, 2024

Are you using the code first approach or model first ?

In either case, can you show me how your model looks like ?

On 10:36PM, Wed 06-May-2015 Michael [email protected] wrote:

Our current project has a model called EventType. I know you can use the
Fluent API to map table names and column names but I can't seem to get it
right with EventType because its an enum and not an entity? Is there a way
to get entity framework to differentiate between the two?

"The type 'TrackerEnabledDbContext.Common.Models.EventType' and the type
'MyProject.Common.Models.EventType' both have the same simple name of
'EventType' and so cannot be used in the same model. All types in a given
model must have unique simple names. Use 'NotMappedAttribute' or call
Ignore in the Code First fluent API to explicitly exclude a property or
type from the model."

I would prefer not to have to change mine and migrate data but if that's
the only solution I can do that.

Thanks for you excellent work!


Reply to this email directly or view it on GitHub
#34.

from tracker-enabled-dbcontext.

ScarlettCode avatar ScarlettCode commented on July 17, 2024

We use code first. (An aside I believe the model first is being retired in EF 7)

namespace MyProject.Common.Models
{
    public class Lecture
    {
    public Lecture()
    {
        LectureLecturers = new List<LectureLecturer>();
    }
    public int? EventTypeId { get; set; }
    public virtual EventType EventType { get; set; }

   //Other fields that aren't important

    }
}

namespace MyProject.Common.Models
{
    public class EventType
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Entity framework basically doesn't know which EventType to point to. Potentially change from an enum to a table so that it can be mapped with Fluent? Goes against the simplicity of the enum though

from tracker-enabled-dbcontext.

bilal-fazlani avatar bilal-fazlani commented on July 17, 2024

I was able to reproduce this and tried a couple of things to fix this. Eventually I found out that there is nothing we can do about it except for changing the name of one of the classes/enum. This is one of the limitation of EF as of now.

References:
http://stackoverflow.com/a/22466391/1365053
http://blog.oneunicorn.com/2013/03/11/ef6-nested-types-and-more-for-code-first/

from tracker-enabled-dbcontext.

ScarlettCode avatar ScarlettCode commented on July 17, 2024

Are you going to make changes at the source to make the EventType name more unique or should I just make changes my side to work around it?

Thanks for looking into it

from tracker-enabled-dbcontext.

bilal-fazlani avatar bilal-fazlani commented on July 17, 2024

No, I don't think it's a good idea to change the name in source as it will break many other people's code.
Please make changes in your code.
Besides, this limitation is supposed to go away in future versions of EF.

from tracker-enabled-dbcontext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.