locked
Trying to create a generic class for ef objects RRS feed

  • Question

  • Hi all,

    I have a number of tables (err, entities) that are not only used to store data, but also used in pop up lists.  So, for example, as you enter the name and info on an employee, a pop up list in a separate window might show all the employees that match what you have typed.

    I am trying to define that popup window.  Now, I know that the actual code to do the lookup for a given entity will be specific to a given class.  But I want to define as much of the interface and internal properties in a basic dialog class and then subclass that for any given entity.

    To that extent, I want to define a generic member that can hold an entity.  In the subclass, I will actually define the correct entity. 

    Then, in my basic dialog class, I can have various methods (virtual or not) that verifies a valid entity has been assigned, can perform generic actions, etc. 

    Any idea on how to do this?  I am looking into generics, but not quite sure has to the best way to do this when using entities.  I know I could always use a basic object reference and use casting to implement it, but find that to be less than desireable.

    Besides just trying to use a generics approach, I am also considering having a facade that I can instantiate that will return the desired entity and then just reference the facade in my dialog base class. 

    Better yet, if someone has such a dialog, that would be even better. 

    Thanks,

    me


    FletcherJ
    Monday, August 29, 2011 11:07 PM

Answers

  • Larcolais,

    Well, I didn't get an answer to my initial question, but I am using a different approach so I don't need it.  What I had wanted was an easy way to define a protected member that would hold a reference to an entity. That reference could then be used to search for data in a generic way with subclasses focusing on the issues specific to the entity being used.

    I am simply implementing an approach that doesn't require one so it is no longer an issue for me.  It wasn't solved, but it no longer needs to be solved (at least not for me, not at this time....)

    Thanks for checking in though.

    me


    FletcherJ
    • Marked as answer by FletcherJ Monday, September 12, 2011 5:12 PM
    Monday, September 12, 2011 5:12 PM

All replies

  • it looks you load different entities into your project dynamically. I think you can check D-linq tech. Check here for more infromation. http://weblogs.asp.net/scottgu/archive/2006/06/04/Using-DLINQ-with-ASP.NET-_2800_Part-2-of-my-LINQ-series_2900_.aspx

    let me know hows going.

    Thanks,

    Werewolf,


    Just a newbie for everything.
    Thursday, September 1, 2011 3:15 AM
  • Werewolf,

    Isn't this essentially LINQ to SQL, the precursor to EF?  In any case, I will look at the code to see if it gives me some ideas on how to model the class the way I want.

    Thanks,

    me

     


    FletcherJ
    Thursday, September 1, 2011 6:55 PM
  • welcome, glad to hear it helps.

    Plus, EF you can check Entity sql and reflector machenism.

    http://msdn.microsoft.com/en-us/library/bb387145.aspx

    http://stackoverflow.com/questions/1077497/is-there-a-way-to-get-entity-id-fields-name-by-reflection-or-whatever

    Thanks,

    Werewolf, 


    Just a newbie for everything.
    Friday, September 2, 2011 4:07 AM
  • Werewolf,

    Well, the stackoverflow link got me started on solving a totally separate problem, so thank you very much. I am going to play with some ideas and see what I can manage.  It may be that I am obsessing over something that I really don't need to worry about right now.  If not, I will come back and dig some more.  And if I get a fix, I will post that as well.

    Thanks for the help.

    me


    FletcherJ
    Saturday, September 3, 2011 1:19 AM
  • Any update? Was your concern solved?

    Please feel free to let us know if you need further support.

    Thanks,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 5, 2011 1:47 AM
  • Larcolais,

    Well, I didn't get an answer to my initial question, but I am using a different approach so I don't need it.  What I had wanted was an easy way to define a protected member that would hold a reference to an entity. That reference could then be used to search for data in a generic way with subclasses focusing on the issues specific to the entity being used.

    I am simply implementing an approach that doesn't require one so it is no longer an issue for me.  It wasn't solved, but it no longer needs to be solved (at least not for me, not at this time....)

    Thanks for checking in though.

    me


    FletcherJ
    • Marked as answer by FletcherJ Monday, September 12, 2011 5:12 PM
    Monday, September 12, 2011 5:12 PM