i hope anybody can help me with this. I use EF6 with TPC (Table per concrete class). There are many tables that are revision save, means every row in the table has the same ID, but multiple versions. One version is the current version (e.g.). 
Table student sample:

```
Id  Version     Name        CurrentVersion
1   1           Murtin      false
1   2           Martin      true
2   1           Reinold     true

```

I use inheritance in my models. The base of all models is EntityBase

```
abstract class EntityBase: IEntityBase
{
    [Key]
    [Column(Order = 0)]
    public int Id { get; set; }
}

```

For all tables that are revision save i use the next base class

```
abstract class RevisionBase : EntityBase, IRevisionBase
{
    [Key]
    [Column(Order = 1)]
    public int Version { get; set; }

    [Required]
    public bool CurrentVersion { get; set; }
}

```

Now my table i work with, of course students

```
class Student: RevisionBase
{
    [Required]
    public string Name{ get; set; }
}

```

So the following code is easy and working

```
new DBContext().Student.FirstOrDefault(s=>s.Id=5 && s.CurrentVersion=true)

```

For uniformly data processing i want to use always the same base method for loading. So i have uniformly error handling and logging. This general get method should always load the current version, if its a versioned table.

```
    private TEntity GeneralGet<TEntity>(int id) where TEntity : EntityBase
    {
        using (var ctx = GetContext())
        {
            if (typeof(IRevisionBase).IsAssignableFrom(typeof(TEntity)))
            {
                var allResultsId = ctx.Set<TEntity>().Where(l => l.Id == id);
                var result = allResultsId.ToList().Cast<IRevisionBase>().FirstOrDefault(r => r.CurrentVersion);
                return result as TEntity;
            }
            else        // ansonsten, bei nicht versionierten Objekten
            {
                var result = ctx.Set<TEntity>().FirstOrDefault(l => l.Id == id);
                return result;
            }
        }
    }

```

This is completely working, but unfortunately i have to load all rows of the same id and filter the current version in memory. (ToList loads all rows with the given id.)

Are there any better ways?

I dont want this "ToList" there. What i need is either a cast to check my current version or maybe mix method chain way and a hard coded filter string. (not nice, but much better than this) I know that this table has a column CurrentVersion. I want to check this before loading all records.