none
How do i map generics? RRS feed

  • Question

  • Hi all,

    Here the simple example:

     

      public interface IPermissionHolder
      {
        int Id { get; set; }
      }
    
      public interface IPermission
      {
        Entity Entity { get; set; }
        IPermissionHolder Holder { get; }
      }
    
      public class Permission<T> : IPermission where T : class, IPermissionHolder 
      {
        public IPermissionHolder Holder
        {
          get { return PermissionHolder; }
        }
    
        public T PermissionHolder { get; set; }
        public Entity Entity { get; set; }
      }
    
      public class User : IPermissionHolder
      {
        public int Id { get; set; }
        public EntitySet<Permission<User>> Permissions { get; set; }
        }
      }
    
      public class Group : IPermissionHolder
      {
        public int Id { get; set; }
        public EntitySet<Permission<Group>> Permissions { get; set; }
      }  <br/>
      public class Entity
      {
        public EntitySet<IPermission> Permissions { get; set; }
      } <br/>
    
    
    Is there a way to define this kind o structure ina DataContext/DBML file?

    Right now my DB is using two different tables for the GroupPermissions and the UserPermissions. I don't like to have a generic table where i have to add a "type" column... with two different table i have a much more strict control.

     

    Thanks for any help

     

    P.S.: i'm still with the Framework 3.5, otherwise i could remove the IPermissionHolder interface and use co-variance.

    Monday, September 13, 2010 3:05 PM

All replies

  • Hi,

    I think I understand where you are going with this but the above doesn't explain clearly about what kind of abstraction do you want to achieve and your current problem domain?

    Also, can you tell what tables are you referring apart from GroupPermission and UserPermission. Do you also have separate User and Group tables in DB? Can you provide details like the table schema and entities in question and how do you want to consume the entities?

    Regards,

    Jay [MSFT]

     

    Friday, September 24, 2010 7:44 PM
  • An idea could be to make a view instead of that table you don't want to create.

    Wednesday, September 29, 2010 1:48 PM