You must make your foreign key nullable:
public class User
{
public int Id { get; set; }
public int? CountryId { get; set; }
public virtual Country Country { get; set; }
}
More Related Contents:
- Code-first vs Model/Database-first [closed]
- Should I enable or disable dynamic proxies with entity framework 4.1 and MVC3?
- How do I detach objects in Entity Framework Code First?
- Order navigation properties when using Include and/or Select methods with EF 4.1 Code-First?
- How do you ensure Cascade Delete is enabled on a table relationship in EF Code first?
- Navigation Property without Declaring Foreign Key
- Entity Framework Code First : Setting up One-To-One foreign key association using Annotations
- Entity Framework Code First Many to Many Setup For Existing Tables
- Entity Framework: One Database, Multiple DbContexts. Is this a bad idea? [closed]
- Ignoring a class property in Entity Framework 4.1 Code First
- Unique Key constraints for multiple columns in Entity Framework
- Entity Framework 6 Code first Default value
- EntityFramework code-first custom connection string and migrations
- EF Code First “Invalid column name ‘Discriminator'” but no inheritance
- EF Code First: How to get random rows
- Debug code-first Entity Framework migration codes
- Entity Framework loading child collection with sort order
- Entity Framework 4.1 default eager loading
- How to pass parameters to the DbContext.Database.ExecuteSqlCommand method?
- mapping private property entity framework code first [duplicate]
- How to create index in Entity Framework 6.2 with fluent configuration
- Mocking or faking DbEntityEntry or creating a new DbEntityEntry
- How to use Entity Framework to map results of a stored procedure to entity with differently named parameters
- EF 4.1 loading filtered child collections not working for many-to-many
- EF Code First foreign key without navigation property
- Entity Framework Code First Using Guid as Identity with another Identity Column
- Using the Entry().CurrentValues.SetValues() is not updating collections
- Model First with DbContext, Fails to initialize new DataBase
- Why does EF5 code first use datetime2 when inserting a nullable datetime into the database?
- Getting exact error type in from DbValidationException