This project has moved. For the latest updates, please go here.

Generic DbSets?

Jan 25, 2014 at 8:22 PM
Edited Jan 25, 2014 at 9:12 PM
In Entity Framework there is a generic "Set" artifact that allow you to write Generic queries without having to know the entity type in advance. So I can write:

var query = from row in DbContext.Set<mytype> ...

In a generic repository.

Is there something similar in BrightstarDB context? If so, I'm overlooking it somehow, and could use a reference. Nothing seems to show up in intellisense.
Jan 28, 2014 at 9:11 AM
I did't find one but I changed context .tt file and added sets to a dictionary and a method on the context so it behaves like you want. It would be better for a set to automatically register with the context in constructor, but until that is done this easy fix should work and it' easy to implement.
Feb 1, 2014 at 7:52 PM
Perhaps you can provide some sample code?
Feb 3, 2014 at 2:18 PM
.tt file code:
public partial class <#=code.Escape(contextClassName) #> : BrightstarEntityContext {
    private static readonly EntityMappingStore TypeMappings;
    private Dictionary<Type, object> _entitySets;
....................................................

private void InitializeContext() 
    {
        _entitySets = new Dictionary<Type, object>();
<#+
    
    foreach(var i in helper.GetDecoratedInterfaces()) {
#>
        
        <#= code.Escape(i.PluralizedName) #> =  new BrightstarEntitySet<<#=i.InterfaceFullName#>>(this);
        _entitySets.Add(typeof(<#=i.InterfaceFullName#>),<#= code.Escape(i.PluralizedName) #>);
        _entitySets.Add(typeof(<#=code.CreateFullName(i.InterfaceNamespaceName, i.ClassName)#>),<#= code.Escape(i.PluralizedName) #>);

<#+
    }
#>

    }

    public BrightstarEntitySet<T> EntitySet<T>() where T : class
    {
        return (BrightstarEntitySet<T>)_entitySets[typeof (T)];
    }
    
<#+
    foreach(var i in helper.GetDecoratedInterfaces())
    {
...............................................
Now you should have "context.EntitySet<T>" method that behaves like you want.
Feb 13, 2014 at 11:04 PM
Thanks!
I'll give it a try this weekend.