First, a little bit of context
I have one desktop application which uses a Paradox database and I am developing a new ASP.NET application using SQL Server to replace the current desktop app.
The transition will happen in tho phases. The first version of the web app will use SQL Server and Paradox at the same time. Legacy entities data will come from Paradox and data from new entities will come from SQL Server. So the desktop and web versions of the app can be used interchangeably.
In the second phase all data from Paradox will be imported to SQL Server. The old desktop app (and the Paradox db) won't be used anymore.
Now, the technical question
Imagine a simple model with two entities:
public class Customer
{
public Int32 ID { get; set; }
public String Name { get; set; }
virtual public IList<User> MyUsers { get; set; }
}
public class User
{
public Int32 ID { get; set; }
public String Name { get; set; }
virtual public Customer MyCustomer { get; set; }
}
public class SqlServerContext : DbContext
{
public SqlServerContext()
{
base.Configuration.ValidateOnSaveEnabled = false;
base.Configuration.LazyLoadingEnabled = true;
base.Configuration.ProxyCreationEnabled = true;
base.Configuration.AutoDetectChangesEnabled = true;
}
public DbSet<User> Users { get; set; }
public DbSet<Customer> Customers { get; set; }
}
When I use only SQL Server for both entities everything works fine. But now I want to retrieve customer data from Paradox and user data from SQL Server.
I then create a repository for the customers, with an underlying OleDbConnection using the Paradox provider. Of course, Entity Framework still creates the Customers table in SQL Server, since User has a Customer property.
I then removed the database relationship (FK) between User and Customer. Now I am able to insert a User related to a Customer, even though they're in different databases.
The problem is: when I try to retrieve a user from db [eg: context.Users.Find(id)] I can read the user's ID and Name, but user.Customer is null. I expected to get the customer ID through the user.Customer.ID property, since this data is in the Users table in SQL Server.
Am I going to the right path? If so, how can EF bring the customer ID for the user?
And if not, what would be a good approach for this scenario? I don't want to expose foreign key properties in the model (i.e: i don't want to have a int CustomerId property in the User entity).
Thanks in advance!