locked
Creating edmx programmatically RRS feed

  • Question

  • Started exploring EF and found it to be useful till we create Entities from selected db objects, there has to be something more in offering which I am not aware till now.

    While looking at designer.cs associated with edmx, found that CREATE operation on entity/ies is generated by default. But there are so many methods which I would not want, like onchange of all the attributes of entities, are there.

    Am thinking of creating edmx through my program, inputs to this would be DB information as stored in storagemodel and entities to be picked from this DB.

    Looking at xml structure of edmx, it looks like a TASK so wanted to check if someone has tried that before!

    Can I set “Code generation strategy” and “Custom tool” for file type .edmx, through C# program.


    Arora S
    Thursday, June 30, 2011 11:45 AM

Answers

  • what I wanted to know that if there is any mechanism through which we can generate this edmx itself.

     

    Take a look at http://huagati.blogspot.com/2010/12/creating-or-modifying-entity-framework.html

    That article describes my wrapper library for EDMX; it makes it easier to read/create/update EDMX models. The library also contains a bunch of built-in LINQ queries against the model metadata that make it easier to find and handle model inconsistencies, and additional ones are easy to write since the entire model is exposed as properties and IEnumerables...

    The online help for the EDMX wrapper lib is available at http://huagati.com/edmxtools/help/ , and if you want to try it out, it ships together with Huagati DBML/EDMX Tools (can be downloaded + trial license at http://huagati.com/edmxtools/ ).


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4

    • Marked as answer by Arora S Monday, July 4, 2011 4:10 AM
    Sunday, July 3, 2011 12:48 PM

All replies

  • Hi,

    I don't know if I understand you at all, but take a look to these other links:

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/b6851eaa-2660-4a60-9308-340b61bc8f14/#c25c5161-fa1d-4cf2-a5bd-337610727885

    http://blogs.msdn.com/b/adonet/archive/2008/01/24/customizing-code-generation-in-the-ado-net-entity-designer.aspx

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Thursday, June 30, 2011 1:30 PM
  • Hi,

    As Reyes says, I'm not quite sure if I understand your needs, but I think I want to supplement Reyes post.

    The way for you to go if you're not satisfied with the code the default edmx generates is by using a Code Generation Item in your project.

    There is several already out there:

    - ADO.NET DBContext Generator (Template to generate EF 4.1 code based on DbContext and DbSet)
    - ADO.NET EntityObject Generator (Template to generate default EF entities)
    - ADO.NET POCO Entity Generator (Template to generate clean POCO entities)
    - ADO.NET Self-Tracking Entity Generator (Template to generate self tracking entities that can be used in a distributed environment)

    When you generate this you will get one or more .tt files in your project which is T4 templates (http://msdn.microsoft.com/en-us/library/bb126445.aspx) which you can modify to suit your needs for entities.

    Since the POCO template (http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx) is the cleanest one, I suggest that you would start with this and modifiy it to suit your needs.


    --Rune
    Thursday, June 30, 2011 6:07 PM
  • Thanks Reyes and Rune for the link you shared

    However everything these links have, starts with having edmx file and then making change in either "Custom tool" or creating a text template from this edmx ,

    what I wanted to know that if there is any mechanism through which we can generate this edmx itself.

    I understand from these links that it might not be possible.

     


    Arora S
    Friday, July 1, 2011 8:44 AM
  • Hi,

    I think EDMXWriter on EF 4.1 do that.

    Here you have a link, but it is in spanish:

    http://geeks.ms/blogs/unai/archive/2011/05/19/ef-4-1-edmxwriter.aspx

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Friday, July 1, 2011 9:14 AM
  • the similar thing I am wondering:

    In POCO usage now is much depend on define the DbSet in DbContext, such as:

    public class TCommonDbContext : DbContext
    {

        public DbSet<TpoTask> TaskSet { get; set; }
    }

     

    Can automatically and  Dynamically Create DbSet when needed?
    so just when I need manipulte some kind of types,  the DbSet of the specific type created at the time.


     


    Hello
    Friday, July 1, 2011 10:01 AM
  • Any update? Would you mind letting us know how it goes?

    Best Regards,


    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.

    Saturday, July 2, 2011 3:08 PM
  • what I wanted to know that if there is any mechanism through which we can generate this edmx itself.

     

    Take a look at http://huagati.blogspot.com/2010/12/creating-or-modifying-entity-framework.html

    That article describes my wrapper library for EDMX; it makes it easier to read/create/update EDMX models. The library also contains a bunch of built-in LINQ queries against the model metadata that make it easier to find and handle model inconsistencies, and additional ones are easy to write since the entire model is exposed as properties and IEnumerables...

    The online help for the EDMX wrapper lib is available at http://huagati.com/edmxtools/help/ , and if you want to try it out, it ships together with Huagati DBML/EDMX Tools (can be downloaded + trial license at http://huagati.com/edmxtools/ ).


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4

    • Marked as answer by Arora S Monday, July 4, 2011 4:10 AM
    Sunday, July 3, 2011 12:48 PM