Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7579501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:41:49+00:00 2026-05-30T17:41:49+00:00

Does anybody have samples for referencing a Code First DbContext from a T4 template?

  • 0

Does anybody have samples for referencing a Code First DbContext from a T4 template?

I have found some T4 examples that use a .dbml as source and also ones that reference a database. I would like to loop through and build javascript files for all the classes in the context. I am having a hard time figuring out how to reference the EnvDTE variable to get the DbContext. From there I will convert to an ObjectContext and loop through the classes to generate the code.

Any ideas or examples?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:41:50+00:00Added an answer on May 30, 2026 at 5:41 pm

    Information wise you could compile the Code First containing assembly down to .dll and then in T4 process load the DLL and read the data from it through reflection.

    We did this kind of approach in a process where we had means to get database => serialization classes, but could not interfere that phase with T4; only after the code generation was done to serialization classes. And in that case it was easier to compile it and then read it through reflection.

    If you go with this approach you have to deal with the fact that you need to build part of the application first, then use T4 generation against that to get the remaining done. In case you’re creating Javascript files, it might make it easier.

    You can make your reflection based T4 as “preprocessed”, so that you can run it in post-build script.

    EDIT: Added seminar presented case demonstration.

    http://abstractiondev.wordpress.com/2012/03/09/microsoft-techdays-2012-finland-adm-materials/

    Download the demonstration from Github, and look at the “T4 Demos.sln” – solution, Advanced7.tt demonstration. It parses types and properties from the given assembly name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody have a short code sample that can be run in the VS
Does anybody have sample code to convert from binary data to string in c#?
Does anybody have a guide to this, containing code samples, tips and an outline
Does anybody have any reference material that details Cauchy-Reed algorithm? Googling for Cauchy-Reed Solomon
Does anybody have a good analogy (or, failing that, a good resource) for describing
Does anybody have a code sample for a unicode-aware strings program? Programming language doesn't
Does anybody have know any sample/tutorial (a sample server using SocketAsyncEventArgs etc) code about
Does anybody have a sample code on how i could open a tif file,
Does anybody know any reasons why IMemAllocator:GetBuffer (Directshow) hangs, apart from all samples being
Does anybody have any experience with different fonts for OCR? I am generating an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.