Can someone explain why the following does not work?
Here are my declarations:
public interface ITableData
{
DateTimeOffset? CreatedAt { get; set; }
bool Deleted { get; set; }
string Id { get; set; }
DateTimeOffset? UpdatedAt { get; set; }
byte[] Version { get; set; }
}
public interface IUser : ITableData
{
string Name { get; set; }
}
public abstract class TableData : ITableData
{
public DateTimeOffset? CreatedAt { get; set; }
public bool Deleted { get; set; }
public string Id { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public byte[] Version { get; set; }
}
public class User : TableData, IUser
{
public User() { }
public string Name { get; set; }
}
Now in my generic repository, I declare a sync table like so:
public abstract class BaseTypedRepository<T> : ITypedRepository<T> where T : ITableData
{
....
public BaseTypedRepository(...)
: base()
{
SyncTable = Client.GetSyncTable<T>();
}
}
And UserRespository inherits BaseTypedRepository like this:
public class UserRepository : BaseTypedRepository<User>, IUserRepository
{...}
So now I understand that UserRepository has a SyncTable of type User defined. and User implements ITableData. So why is the following not working:
IMobileServiceSyncTable<ITableData> tbl = userRepository.SyncTable;
How can I treat each repository's SyncTable as a generic IMobileServiceSyncTable of ITableData?
Edit 1 By "not working" I mean that the line above will not compile due to "Cannot implicitly convert IMobileServicesSyncTable to IMobileServicesSyncTable. An explicit conversion exists. Are you missing a cast?".
When I do:
IMobileServiceSyncTable<ITableData> tbl = repository.SyncTable as IMobileServiceSyncTable<ITableData>;
The line compiles but after I run the code (even after adding class to BaseTypedRepository constraints), tbl is null.
IMobileServiceSyncTable is part of Microsoft Mobile Client SDK found here (https://github.com/Azure/azure-mobile-services/blob/master/sdk/Managed/src/Microsoft.WindowsAzure.MobileServices/Table/Sync/IMobileServiceSyncTable.Generic.cs).