I'm trying to use Silverlight with RIA services. CRUD operations are pretty easy. But I am stuck with the "not exists" case.
I have two entities Person (personID, personName) and Car(carID, personID). Some person have a car, but only one car.
internal sealed class Person
{
private PersonMetadata() { }
public int personID { get; set; }
public string personName { get; set; }
[Include]
public Car CarNavigation { get; set; }
}
internal sealed class Car
{
private CarMetadata() { }
public string carName { get; set; }
public int personID { get; set; }
}
public IQueryable<Person> GetPersonEager()
{
return this.ObjectContext.Person.Include("CarNavigation");
}
<sdk:DataGrid Name="PersonGrid" AutoGenerateColumns="False">
<sdk:DataGrid.Columns >
<sdk:DataGridTextColumn Binding="{Binding personID}" />
<sdk:DataGridTextColumn Binding="{Binding personName}" />
<sdk:DataGridTextColumn Binding="{Binding CarNavigation.carName}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
PersonGrid.ItemsSource = context.Person;
context.Load(context.GetPersonEager());
This structure works pretty well, for update. I also can update the car's name.
But, I also want to list the persons who does not have a car. And I also want to be able to add cars to them. I have tried:
public IQueryable<Person> GetPersonEagerWhoDoesNotHaveACar()
{
return this.ObjectContext.Person.Include("CarNavigation").Where( x => x.CarNavigation == null );
}
The method above returns me the persons without cars, but the Car entity is empty. How sould I modify this to make it return the persons without cars and the car entity's key is filled.