Please tell me the meaning of this error?
{"One or more validation errors were detected during model
generation:\r\n\r\nMvcDemo.Models.Employee: : EntityType 'Employee'
has no key defined. Define the key for this EntityType.\r\nemp:
EntityType: EntitySet 'emp' is based on type 'Employee' that has no
keys defined.\r\n"}
Related
I am trying to update the Product entity and getting the following error
"internalexception":{ "message":"A type named 'Product' could not be
resolved by the model. When a model is available, each type name must
resolve to a valid
type.","type":"System.InvalidOperationException","stacktrace":" at
Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataEntityDeserializer.ReadODataBody[T](HttpRequestMessage
request)" }
I have used OData Connected Service in VS2017 to generate the proxy class and trying to update by calling these resources and following is the code for updating the entity record
DataServiceCollection<Product> products = new DataServiceCollection<Product>(context.ODataResources, "Products", null, null);
products.Add(product); //here product is the entity object that needs to be updated.
var productTobeUpdated = products.FirstOrDefault();
productTobeUpdated.property = value;
context.ODataResources.UpdateObject(productTobeUpdated);
_context.ODataResources.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties)
Can anyone help me with this?
[ForeignKey("Creator")]
public string CreatorID {get;set;}
public virtual ApplicationUser Creator {get;set;}
I have a model which I want to save the creator and modifier.
But there are errors during migration
TSRDTEST.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
TSRDTEST.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
I'm using built in login/logout/register template,with database column prefixs "AspNet", is there any way to fix that error without modify entire project project and preserve the columns with prefix AspNet, Thanks
Actually I didnt understand what you want to do. But the mapping between entities should be look like this.
public string CreatorID {get;set;}
[ForeignKey("CreatorID ")]
public virtual ApplicationUser Creator {get;set;}
I have some models classes that inherit from a single abstract class, which in turn is deriving from BaseEntity
public abstract class Item: BaseEntity
When I try create an Entity Data Model on my context I get the following error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
DataLayer.EntityAspect: : EntityType 'EntityAspect' has no key defined. Define the key for this EntityType.
DataLayer.EntityKey: : EntityType 'EntityKey' has no key defined. Define the key for this EntityType.
DataLayer.MetadataStore: : EntityType 'MetadataStore' has no key defined. Define the key for this EntityType.
DataLayer.Validator: : EntityType 'Validator' has no key defined. Define the key for this EntityType.
DataLayer.DataType: : EntityType 'DataType' has no key defined. Define the key for this EntityType.
DataLayer.StructuralType: : EntityType 'StructuralType' has no key defined. Define the key for this EntityType.
DataLayer.ValidationError: : EntityType 'ValidationError' has no key defined. Define the key for this EntityType.
DataLayer.ValidationContext: : EntityType 'ValidationContext' has no key defined. Define the key for this EntityType.
DataLayer.StructuralProperty: : EntityType 'StructuralProperty' has no key defined. Define the key for this EntityType.
EntityAspects: EntityType: EntitySet 'EntityAspects' is based on type 'EntityAspect' that has no keys defined.
EntityKeys: EntityType: EntitySet 'EntityKeys' is based on type 'EntityKey' that has no keys defined.
MetadataStores: EntityType: EntitySet 'MetadataStores' is based on type 'MetadataStore' that has no keys defined.
Validators: EntityType: EntitySet 'Validators' is based on type 'Validator' that has no keys defined.
DataTypes: EntityType: EntitySet 'DataTypes' is based on type 'DataType' that has no keys defined.
StructuralTypes: EntityType: EntitySet 'StructuralTypes' is based on type 'StructuralType' that has no keys defined.
ValidationErrors: EntityType: EntitySet 'ValidationErrors' is based on type 'ValidationError' that has no keys defined.
ValidationContexts: EntityType: EntitySet 'ValidationContexts' is based on type 'ValidationContext' that has no keys defined.
StructuralProperties: EntityType: EntitySet 'StructuralProperties' is based on type 'StructuralProperty' that has no keys defined.
at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.DbContextPackage.Handlers.ViewContextHandler.ViewContext(MenuCommand menuCommand, Object context, Type systemContextType)
If I remove the BaseEntity inheritance and create an Entity Data Model, it completes successfully. What is BaseEntity doing to break my model?
The real world problem is that when I am attempting to return the metadata from the DataService.Metadata() call it hits this error too.
Any ideas how to get around this?
Thanks
Ended up using a "hack" whereby my server side entity models did not derive BaseEntity, but my client side entity models did. I accomplished this by using partial classes, and file links in VS
I'm trying to configure an MVC 4 application using EF 5 against the System.Web.Providers Membership DB. The ADO.NET Entity Data Model appears correct. The classes generated by the EF 5.x code generator look ok, but do not have a [Key] attribute. When I try to create a User Controller, I get the following error:
Microsoft Visual Studio
Unable to retrieve metadata for 'Citrius.Admin.User'. One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'Membership' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'Profile' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Memberships' is based on type 'Membership' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Profiles' is based on type 'Profile' that has no keys defined.
I thought I saw a walkthrough of this, using these versions, but cannot find it. I've tried to find a solution but all the examples are of previous versions.
Am I too far out on the bleeding edge?? Any help would be appreciated...
Why dont you assign the Key manually?
Go into each one and add [Key] above the field that should be the Key.
That should get rid of these errors.
I am making an application using MVC 3.0 Razor and Code First Entity Framework.
I am wondering how to define primary key and Foreign Key Relation in the Model.
I know how to define Primary Key.using Key attribute.
for example, I define [Key] attribute in the Model Table Class for Primary Key.
But, really don't know how to define Foreign Key for column in class.
Please Help..................
You can just make a List<ChildType> property in the parent class and a ParentType property in the parent class.
EF will generate the key automatically.