I use WCF dataservices CTP2 + EF4.1 in my project.
I want to update an entity object using wcf data service.
Here is my object:
public partial class Company
{
[Required]
public virtual User Manager { get; set; }
public Guid Manager_Id { get; set; }
}
Then I transfer my company object to server there wcf service is stored, Manager property is null, but its foreign key Manager_Id is assigned to real manager object.
In my ef data model I have defined foreign key:
modelBuilder.Entity<Company>().HasRequired(t => t.Manager)
.WithMany(t => t.Companies)
.HasForeignKey(d => d.Manager_Id);
The problem is that it still throwing the exception that entity cannot be saved cause of validation error (manager property is required). So my question is how can I tell to wcf to save required property using its foreign key if required objects are null?
The workaround
modelBuilder.Entity<Company>().Property(x => x.Manager_Id).HasColumnName("Manager_Id");
also makes no effect.
I found workaround solution. Just putted validation off on wcf service side.