1

I was trying to optimize the performance for my site so i followed these rules while doing the point about Generating views on compile time i had to create .edmx file, after creating this file and follow all the steps I'm facing this issue:

Schema specified is not valid. Errors: 
The property for the relationship 'FK_dbo_X_dbo_Y_x_id' contains a Role 'X' has a type 'Site.Models.X' that is not valid for a relationship End. Change the End Role to an EntityType.

for every relation i have.

can anyone tell me how can i fix this error?

Update :

How i define my relations

in model :

    [ForeignKey("foreign_id")]
    public EntityCollection<MyClass> relation_obj { get; set; }

in DbContext:

modelBuilder.Entity<X>().HasMany(m => m.relation_obj );

The relation assembly :

[assembly: EdmRelationshipAttribute("DBModel", "FK_dbo_X_dbo_Y_x_id", "X", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Site.Models.X), "Y", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(Site.Models.Y), true)]
5
  • 1
    Could you show code with your optimizations? Commented Feb 28, 2013 at 6:06
  • I've added a new edmx file so it automatically created new models for every table i have, so i deleted the model and modified the designer and the assembly refs to use the old models like the following : [assembly: EdmRelationshipAttribute("DBModel", "FK_dbo_X_dbo_Y_restaurant_id", "X", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Site.Models.X), "Y", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(RestaurantApp.Models.Y), true)] and added the pre-build script like they said here: http://msdn.microsoft.com/en-us/library/bb896240.aspx Commented Feb 28, 2013 at 6:12
  • Mr. @KirillBestemyanov if you need any other peace of information please tell me, your help will be very appreciated ! Commented Feb 28, 2013 at 6:32
  • 1
    Is Site.Models.X and Site.Models.Y EntityFramework generated classes or your defined classes? Commented Feb 28, 2013 at 6:49
  • My own classes, the old models i used to use Commented Feb 28, 2013 at 7:12

1 Answer 1

1

Your problem is that you define as navigation properties classes that has not mapping to database (your own defined classes). Don't do it. Entity framework cannot work with such navigation properties. You can read more about navigation properties here.

Problem is here:

[assembly: EdmRelationshipAttribute("DBModel", "FK_dbo_X_dbo_Y_x_id", "X", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Site.Models.X), "Y", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(Site.Models.Y), true)]

From MSDN:

"

public EdmRelationshipAttribute(
    string relationshipNamespaceName,
    string relationshipName,
    string role1Name,
    RelationshipMultiplicity role1Multiplicity,
    Type role1Type,
    string role2Name,
    RelationshipMultiplicity role2Multiplicity,
    Type role2Type
)

Parameters

relationshipNamespaceName Type: System.String The name of the namespace for the association in which this entity participates.

relationshipName Type: System.String The name of a relationship in which this entity participates.

role1Name Type: System.String Name of the role for the type at one end of the association.

role1Multiplicity Type: System.Data.Metadata.Edm.RelationshipMultiplicity A value of RelationshipMultiplicity that indicates the multiplicity at one end of the association, such as one or many.

role1Type Type: System.Type The type of the entity at one end of the association.

role2Name Type: System.String Name of the role for the type at the other end of the association.

role2Multiplicity Type: System.Data.Metadata.Edm.RelationshipMultiplicity A value of RelationshipMultiplicity that indicates the multiplicity at the other end of the association, such as one or many.

role2Type Type: System.Type The type of the entity at the other end of the association. "

So role1Type and role2Type should be entities. Not your own defined classes.

Sign up to request clarification or add additional context in comments.

2 Comments

Sir, I think that i didn't get your point very well, my navigators are mapped to the database through DbContext just like the following :modelBuilder.Entity<X>().HasMany(m => m.relation_obj ); and it was working previously. Sir, I really appreciate your help. thanks alot!
Here is Site.Models.Y and Site.Models.X that is not EF classes:[assembly: EdmRelationshipAttribute("DBModel", "FK_dbo_X_dbo_Y_x_id", "X", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Site.Models.X), "Y", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(Site.Models.Y), true)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.