Hi Rick. Thanks for the repro solution (btw, next time please don't include any dll/bin/etc files, just code).
Now, I see what is happening: you generated code using TwoClasses preset. That creates a second entity that inherits from the original. For instance UserEntity and MyUserEntity, those are located on your \EntitySubClasses folder.
So this code:
metaData.GetQueryableForEntity((int)Enum.Parse(typeof(EntityType), typeof(T).Name))
actually returns an instance of
DataSource2<MyUsersEntity>
, because that is specified in the LinqMetaData class because those are the entities you work on at the end (where your custom logic is placed). Later you cast that to DataSource2<UsersEntity> which is not defined as a valid datasource in the LinqMetaData.
So, before go on, an advice is that if you are not really using the TwoClasses preset benefit, just use the normal preset that generates one class. You still can add custom code in partial classes.
Now, the next code snippet fixes the problem. Basically you ask for an IQueriable<MyUserEntity> and when you call GetQueryableForEntity use its parent (UserEntity). This is the only way as your code is pretty generic.
public static IQueryable<T> Get<T>() where T : CommonEntityBase
{
var adapter = new GameDBAdapter();
var metaData = new LinqMetaData(adapter);
var dataSource = metaData.GetQueryableForEntity((int)Enum.Parse(typeof(EntityType), typeof(T).BaseType.Name)) as DataSource2<T>;
var result = from data in dataSource
select data;
return result;
}
static void Main(string[] args)
{
var foo = Get<MyUsersEntity>();
}
Hope helpful