I am using entity framework 4.1 code first.
I have a GrantApplication class:
public class GrantApplication
{
// Just some of the properties are listed
public int Id { get; set; }
public GrantApplicationState GrantApplicationState { get; set; }
}
GrantApplicationState is an enum and looks like this:
public enum GrantApplicationState
{
Applying = 1,
Submitted = 2,
cknowledged = 3
}
Just before I go and add the grant application the database I set the grant application state:
public void Insert(GrantApplication grantApplication)
{
// Set the current state to applying
grantApplication.GrantApplicationState = GrantApplicationState.Applying;
// Insert the new grant application
grantApplicationRepository.Insert(grantApplication);
}
In my database I have a GrantApplication table with a GrantApplicationStateId that links to a GrantApplicationState table.
How do I get EF to add the state id from GrantApplication.GrantApplicationState to the GrantApplicationStateId column? Is this possible? And when I retrieve the GrantApplication object then it will need to be set as well. Is this the way to do it or do I have to create another property in my GrantApplication class called GrantApplicationStateId?