asp.net mvc - Null value in database relation using EF code first -


i have 2 class customers , membershiptype , has structure. when creating database, column membershiptype has null value. how can fix it?

public class customer {     public int customerid { get; set; }     [required]     public string customername { get; set; }     [required]     public string customergender { set; get; }     public byte age { set; get; }     public bool issubscribedtonewsletter { set; get; }     public membershiptype membershiptype{ get; set; }     public byte membershiptypeid { set; get; } }   public class membershiptype {     [key]     public byte memebershipid { set; get; }     public short signupfee{ get; set; }     public byte durationinmonth { set; get; }     public byte discountrate { get; set; } } 

customers table

  cusid custname  cusgender age  issub.. membershiptypeid  membershiptype_membershipid    1     jobin       male    27      0          2            null 

migration:

  createtable(             "dbo.customers",             c => new                 {                     customerid = c.int(nullable: false, identity: true),                     customername = c.string(),                     customergender = c.string(),                     age = c.byte(nullable: false),                     issubscribedtonewsletter = c.boolean(nullable: false),                     membershiptypeid = c.byte(nullable: false),                     memebershiptypes_memebershipid = c.byte(),                 })             .primarykey(t => t.customerid)             .foreignkey("dbo.membershiptypes", t => t.memebershiptypes_memebershipid)             .index(t => t.memebershiptypes_memebershipid); 

i see couple of possible problems.

  1. try consistent spelling... customer has "membershiptypeid" foreign key primary key of "membershiptype" "memembershipid". happens if make key of membershiptype membershiptypeid? convention-based configuration of ef getting confused?

  2. ef not 1-to-1 relationships...when creates them wants primary key of dependent the same value primary key of primary http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -