none
Incompatible project project class library? RRS feed

  • Question

  • Hi to all,
    I received this error when i run a solution with: "project MVC 3" + reference of "project class library". (entity framework 4.1)
    One or more validation errors were detected during model generation:
    System.Data.Edm.EdmEntityType: : EntityType 'Model1' has no key defined. Define the key for this EntityType.
    System.Data.Edm.EdmEntitySet: EntityType: EntitySet ?tables_test? is based on type ?Model1? that has no keys defined.
    My problem is, i have a "project class library" with my model:
    CODE 1:
    namespace MODELS
    {
        public class Model1
        {
            //Modelo
            [Key, Column(Order = 0)] public int clave1_id { get; set; }
            [Key, Column(Order = 1)] public int clave2_id { get; set; }              
            [Required]
            [StringLength(20)]
            public string values { get; set; }
        }
    }


    I had test with it is code, i haven't problem, with only one [key]:
    CODE 2:
    namespace MODELS
    {
        public class Model1
        {
            //Modelo
            [Key] public int clave1_id { get; set; }
            public int clave2_id { get; set; }              
            [Required]
            [StringLength(20)]
            public string values { get; set; }
        }
    }

    Any more.... I remove class "Model1" of "project class library" and move it class with CODE1 to "project MVC". I haven't it problem :?
    Incompatible project "project class library" with entity framework :?
    Thank you very much in advance for your answer!
    • Edited by David Plaza Wednesday, December 14, 2011 11:07 AM Insert Code Block
    Wednesday, December 14, 2011 11:06 AM

Answers

  • Thanks Alan, the problem was the version of library entityframework. A project was 4.2.0.0 and other 4.1.0.0 :)

     

     


    David S. Plaza
    • Marked as answer by David Plaza Thursday, January 26, 2012 3:29 PM
    Thursday, January 26, 2012 3:28 PM

All replies

  • Hi David,

    Not sure about your scenario, I test to move the model to other class libary(add EntityFramework.dll and System.ComponetModel.DataAnnotations.dll), it works with two [Key] decrations.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations;
    using ClassLibrary1;
    
    namespace Consolekey
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var db= new MyContext())
                {
    
                    db.Database.CreateIfNotExists();
                }
            }
        }
        public class MyContext : DbContext
        {
            public DbSet<Blog> Blogs { get; set; }    
        }
    }
    ------------------------
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel.DataAnnotations;
    
    namespace ClassLibrary1
    {
        public class Blog
        {
            [Key, Column(Order = 0)]
            public int ID1 { get; set; }
            [Key, Column(Order = 1)]
            public int ID2 { get; set; }
            public string Name { get; set; }
    
        }
    }
    
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 19, 2011 9:24 AM
    Moderator
  • Thanks Alan, the problem was the version of library entityframework. A project was 4.2.0.0 and other 4.1.0.0 :)

     

     


    David S. Plaza
    • Marked as answer by David Plaza Thursday, January 26, 2012 3:29 PM
    Thursday, January 26, 2012 3:28 PM