1

I'm hoping to scaffold a bunch of web forms pages using asp.net dynamic data. The tutorials fit in nicely when going directly into Entity Framework. However we are using generic repositories (to provide a multi tenancy layer), does anyone have any examples of how a repository pattern can work with dynamic data?

Alex KeySmith
  • 16,657
  • 11
  • 74
  • 152

1 Answers1

1

I'm doing Linq to SQL with a Repository pattern, and EF with repository pattern is possible also.

public class BaseRepository : IDisposable
    {
        protected MyDataContext dc = null;
        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();        
        protected BaseRepository()
        {
            dc = new MyDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString, mappingSource);
        }
    }

I have an interface to my Object Repository :



interface IObjectRepository
    {
    ...
    }

and the object Repository:



public class ObjectRepository : BaseRepository, IObjectRepository
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public ObjectRepository()
        {
                IList<Foo> GetFoos = GetFoos()
{
...
}
        }
    }
Ash Machine
  • 9,601
  • 11
  • 45
  • 52
  • Interesting thanks @Ash, are you able to use this with DynamicData? – Alex KeySmith Mar 22 '12 at 22:15
  • Yes, I have it working in Dynamic Data 4.0. I just use a partial class to add DD metadata on top of the DBML designer file that the L2S provides. – Ash Machine Mar 22 '12 at 22:25
  • Thanks Ash, the particular problem I'm having at the moment is tying the pagetemplates to a repository. As by default they are using the entitydatasource, I'm guessing I need to find a way of using the objectdatasource but somehow detecting which repository to use? Or have you gone the other route and avoided pagetemplates (which I'm doing at the moment). – Alex KeySmith Mar 23 '12 at 09:17