when i submit, i cant insert the data to database.
i used breakpoint and it seems my auto icrement id returns zero.
this is my model
public int ContactID { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string Code { get; set; }
public string Status { get; set; }
The reason you cannot get the auto-increment ID to come back is because your context (database) is different from your model layer (or, at least, EntityFramework/Code-First thinks it is). If you are using code-first, try the following in the nuget package command console:
update-database
Or, try:
update-database -force
See this article for more info The model backing the <Database> context has changed since the database was created
See the following as a reference of the various code-first commands https://coding.abel.nu/2012/03/ef-migrations-command-reference/
Update-Database
Applies any pending migrations to the database.
-Force
Specifies that data loss is acceptable during automatic migration of the database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.