Comments (5)
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.
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.
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.
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.
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)
- [DataType(DataType.Date)] HOT 1
- Entry as Modified not traking the changes. HOT 3
- Is there any to use it in Databse first ?
- error The entity type AuditLog is not part of the model for the current context HOT 7
- Static configuration is bad for multiple contexts HOT 2
- Given key was not present in the dictionary HOT 2
- Using of deprecated dependency EntityFramework.MappingAPI HOT 35
- Datetime2 conversion error when saving HOT 1
- System.Collections.Generic.KeyNotFoundException HOT 1
- Could not load file or assembly 'EntityFramework.MappingAPI, Version=6.1.0.9, Culture=neutral, PublicKeyToken=7ee2e825d201459e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) HOT 3
- Multiple SELECT queries with GlobalTrackingConfig.DisconnectedContext = true HOT 3
- TrackerIdentityContext only tracking related objects
- Nuget package HOT 11
- Target .netstandard2.1, netcoreapp3.1, and entity framework 6.3/6.4 HOT 2
- Getting AuditLogDetail for properties of complex types.
- Version to EntityFrameworkCore and Identity Core HOT 1
- Global level tracking does not work HOT 1
- No tracking done HOT 1
- AuditLogs inserted after SaveChanges fail + Reload HOT 1
- Support with Efcore 7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tracker-enabled-dbcontext.