Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wish to Create A Code First Approach in a Database But
I Keep on Getting This Error When I Generate a Controller
I Always Get This Error Message

Unable To Retrieve Metadata for 'Identifications.Models.Identification'.
Value Cannot be null
Parameter name: key

This is my Model so Far

C#
namespace Identifications.Models
{
    public class Identification
    {

        public Int32 ID { get; set; }
        public string FullName { get; set; }
        public HttpPostedFileBase file { get; set; }

    }

    public class DbIdentification : DbContext
    {

        public DbSet<Identification> Identifications { get; set; }
    }
}


This is my ConnectionString so Far

C#
<connectionstrings>
    <add name="DbIdentification">
         <connectionString="server=.; database=Sample; Integrated Security=SSPI"
          providerName="System.Data.SqlClient"/>    
</connectionstrings>




Hope You Can Help me Out Here A Big Thanks!
Posted
Updated 1-Sep-14 1:16am
v4

 
Share this answer
 
EF require PK on each table so you need this
C#
namespace Identifications.Models
{
public class Identification
{

[Key]
public Int32 ID { get; set; }
public string FullName { get; set; }
public HttpPostedFileBase file { get; set; }

}


you can use more options from here
http://msdn.microsoft.com/en-in/data/jj591583.aspx[^]
 
Share this answer
 
v2
This is code first entity framework, you are using so the Sql needs to know which is the primary key, it is going to set. So [key] attribute is needed.
Follow here[^]
Above link would give you code first conventions.
Thanks
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900