locked
Class decoration for DB First RRS feed

  • Question

  • Hi,

    How is it possible to add the actual db table name by modifying the tt?

    Thanks,

    Ivan

    Monday, June 4, 2012 1:07 PM

Answers

  • Hi Cryo75,

    Welcome to MSDN Forum.

    I have already replied your another thread about how to get actual table name from an entity, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Cryo75 Tuesday, June 5, 2012 1:24 PM
    Tuesday, June 5, 2012 5:21 AM

All replies

  • Hi,

    When you are using DB First this information should be part of the EDMX. Else you are looking perhaps at http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.tableattribute ? Not sure what you are doing ? You are trying to pass from a DB first model to a Code First model ?

    I never tried this but IMO when I'll use Code First over an existing database I'll likely just ty to query the information schema views to generate directly the code I would have typed by hand rather than going through the EDMX file step and then using and tweaking the tt template...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Monday, June 4, 2012 1:17 PM
  • I would like to modify the T4 template so that on entity generation, my entities will have the following decoration automatically:

    [Table(Name = "table_name_here")]

    Monday, June 4, 2012 1:20 PM
  • Try : http://msdn.microsoft.com/en-us/library/ff477603.aspx and http://stackoverflow.com/questions/8997442/getting-the-namespace-for-an-edmx-in-a-t4-template

    My understanding is that you look at loading EDMX metadata to use them in your custom TT template. I'll give this a try if it still doesn't work though I'm not sure to understand your overall goal (once again you want to move from EDMX based code to Code First code with EDMX being finally totally unused ?).

    I'm asking because http://blogs.msdn.com/b/adonet/archive/2011/05/18/ef-power-tools-ctp1-released.aspx might already do this (i.e. it takes a database and generate the code first code without ever using an EDMX file).

    It's often better to give an overview of your general goal as sometimes it allows one to suggest another and possibly simpler approach...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Monday, June 4, 2012 3:04 PM
  • My general goal is that I can get the table name from the entity's attribute because that's the easy way I find.
    Monday, June 4, 2012 6:20 PM
  • Hi Cryo75,

    Welcome to MSDN Forum.

    I have already replied your another thread about how to get actual table name from an entity, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Cryo75 Tuesday, June 5, 2012 1:24 PM
    Tuesday, June 5, 2012 5:21 AM