Entity Framework and migration issue -


this sample class

public class contacts {     [key]     public int contactid { get; set; }      public string phone { get; set; }     public string fax { get; set; }     public bool isdefault { get; set; }      public int addressid { get; set; }     public virtual addresses customer { get; set; }   } 

in our database ef create table contacts. add 1 new field contact class , public bool isdefault { get; set; }

when try migrate way

enable-migrations add-migration addisdefault update-database -verbose 

then vs show new fields added. sql got package manager console like

alter table [dbo].[contacts] add [isdefault] [bit] not null default 0 alter table [dbo].[customers] add [address1] [nvarchar](max) alter table [dbo].[customers] add [address2] [nvarchar](max) alter table [dbo].[customers] add [phone] [nvarchar](max) alter table [dbo].[customers] add [fax] [nvarchar](max) insert [dbo].[__migrationhistory]([migrationid], [contextkey], [model],  [productversion]) values (n'201609071306198_addisdefault', n'eftest.testdbcontext', 

i though new fields has been added when query contacts table saw no new field has been added.

migration details

namespace eftest.migrations {     using system;     using system.data.entity.migrations;      public partial class addisdefault : dbmigration     {         public override void up()         {             addcolumn("dbo.contacts", "isdefault", c => c.boolean(nullable: false));             addcolumn("dbo.customers", "address1", c => c.string());             addcolumn("dbo.customers", "address2", c => c.string());             addcolumn("dbo.customers", "phone", c => c.string());             addcolumn("dbo.customers", "fax", c => c.string());         }          public override void down()         {             dropcolumn("dbo.customers", "fax");             dropcolumn("dbo.customers", "phone");             dropcolumn("dbo.customers", "address2");             dropcolumn("dbo.customers", "address1");             dropcolumn("dbo.contacts", "isdefault");         }     } } 

i did not write code seed. reason new field has not been added contacts table ?

please guide me why new field called isdefault not being added table event after migration command issuing ? thanks

my updated post

public class testdbcontext : dbcontext     {         public testdbcontext()             : base("name=testdbcontext")         {         }          public dbset<customer> customer { get; set; }         public dbset<addresses> addresses { get; set; }         public dbset<contacts> contacts { get; set; }     } 

connection string in app.config file

  <connectionstrings>     <add name="testdbcontext" connectionstring="data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\db\testdb.mdf;integrated security=true"       providername="system.data.sqlclient" />   </connectionstrings> 

issue solved

problem @ end.

my connection string looking

ef migration not understand meaning of datadirectory path

the moment hard code db file path below connection issue solved.

  <connectionstrings>     <add name="testdbcontext" connectionstring="data source=(localdb)\v11.0;attachdbfilename=c:\users\user1\documents\visual studio 2013\projects\eftest\eftest\db\testdb.mdf;integrated security=true"       providername="system.data.sqlclient" />   </connectionstrings> 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -