none
Entity Framework - Base Class RRS feed

  • Question

  • Hi,

    I use EF4 and in my edmx file I have 4 entities. Each entity has "Modified", "ModifiedBy", "Created", CreatedBy" attributes.

    Is it possible to create a base class (in edmx designer) which are not a mapping with a table but which contains these attributes ?

    And in my Business Layer, I could use this class to create generic Manager...

    thanks

    • Moved by Min ZhuModerator Monday, October 3, 2011 6:02 AM (From:Windows Presentation Foundation (WPF))
    Thursday, September 29, 2011 11:19 AM

All replies

  • You can modify T4 Templates which generating the EDM Objects.

    Look at this hint:

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

     

    Thursday, September 29, 2011 11:39 AM
  • OK fo generating class objects (and change base class) in tt file... 

    but in edmx designer, if I create EntityBase with attributes.... then designer will create automatically "EntityBase" table...  it's not good for me..

    I want, in my DataBAse : 

     - Client (Id, Name, ModifiedBy, Modified, Created, CreatedBy)

    In my model : 

     - EntityBase (Id, ModifiedBy, Modified, Created, CreatedBy)

     - Client (Name) (inherit from EntityBase)

    Thursday, September 29, 2011 12:14 PM
  • Hi CaptainChoc,

    You can add EntityBase(base properties) in EDMX--->Right Click Edmx-->Add Inheritance-->Select Based class--->Remove the properties from Client entity--->Right Click EntityBase entity--->Table Mapping---->mapping to Client(map the properties in client entity)

    Have a nice day.

     


    Alan Chen[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, October 3, 2011 9:37 AM
    Moderator
  • And for others class, for example, 

     

     I want, in my DataBAse : 

     - Client (Id, Name, ModifiedBy, Modified, Created, CreatedBy)

     - Project (Id, ClientId, Name, ModifiedBy, Modified, Created, CreatedBy)

    In my model : 

     - EntityBase (Id, ModifiedBy, Modified, Created, CreatedBy)

     - Client (Name) (inherit from EntityBase)

     - Project(ClientId, Name) (inherit from EntityBase)

     

     

    Is it the same procedure ?


    • Edited by CaptainChoc Wednesday, October 5, 2011 8:29 AM
    Wednesday, October 5, 2011 8:28 AM
  • Hi Captain,

    Right!

    Change EntityBase's Abstract property to "True".

     using (var context = new EFTestEntities2())
                {
                    var e = context.BaseEntities.OfType<Client>();
                }
    

    Have a nice day.


    Alan Chen[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.

    Wednesday, October 5, 2011 8:46 AM
    Moderator
  • I tried this solution, but when I generate the sql, I have one Table "ObjectBase" and an other Table "ObjectBases_CLient".

    Is it not possible to have only one "Client" table which contains "ObjectBase" attributes ?

    Wednesday, October 5, 2011 9:00 AM