locked
Entity Framework reference in Dynamic data project RRS feed

  • Question

  • User1812187139 posted

    Hey,

    I have created a Entity Framework (EF) project and referenced it in a Dynamic Data (DD) project. I am able to run the project to show all the tables (ScaffoldAllTables =true) . Now I want scaffold selected tables and fields in the DD project.  How do you do this in the DD project without partial classes. If you put the partial classes the EF project then it cannot be reused elsewhere. 

    Are you supposed to recreate or copy the EF model for every subject area of a database to different DD projects to show different table/fields?.  How do you reuse the same EF model in different projects or is this not possible and there is a different EF for every DD.

     

    Thanks!!

     

     

     

    Wednesday, November 19, 2008 9:54 PM

Answers

  • User-1005219520 posted

    Why not have just one data model, one set of Primary partial classes (you can add more partial classes to specific sites) - then simply create hard links rather than copies. Any changes made will be instantly reflected in the others. That's what I'm doing right now with 4 web sites ( EF original, EF modified, L2S original, L2S modified) - they all share the same site.master(.cs) - so I can navigate to any of the 4 sites to make comparisons. They all easily share the same DB via the connection string  but I currently have a copy of the EF and L2S data model. I'll move to the hard link approach.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 1:51 PM
  • User-1005219520 posted

    Hard links have nothing to do with DD, they are used in unix and windows (NTFS) to point to a file on the disk. All the files on your disk are hard links. The following commands makes a new hard links pointing to the original file.


    S:\code\DD\EF\L2S>mklink /h site.master  ..\rb\site.master
    Hardlink created for site.master <<===>> ..\rb\site.master

    S:\code\DD\EF\L2S>mklink /h site.master.cs  ..\rb\site.master.cs
    Hardlink created for site.master.cs <<===>> ..\rb\site.master.cs

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:35 PM

All replies

  • User660823006 posted

    I think you have a couple of options here:

    a) You could create a metadata class in your class library that contains EF and it could use IFDEF's to enable a different block of partial classes on a per project basis.

    b) You could use our metadata at runtime sample from futures to inject your metadata at runtime which means it would just affect the current instance. http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14475

    c) You copy the EDMX file into multiple projects.

     

    Thursday, November 20, 2008 2:32 AM
  • User1812187139 posted

    Hey Thanks,

    a) by IFDEfs I assume you mean compiler switches to produce different dlls to be targeted at the DD.

    b) There are a lot of projects and files in the solution.  What project has injection code.  Would you inject in the DD project?

    c) Ya got that one.

     

    Thursday, November 20, 2008 1:04 PM
  • User660823006 posted

    Does this help: 

    a) Something like:

    #if FOO

    [DisplayName("test")]

    #endif

    b)

    // Example of adding metadata attributes programmatically
    InMemoryMetadataManager.AddColumnAttributes<Product>(p => p.UnitsInStock,
        new RangeAttribute(0, 1000) { ErrorMessage = "This field must be between {1} and {2} [from InMemoryMetadataManager]." }
    );

    model.RegisterContext(typeof(NorthwindDataContext), new ContextConfiguration() {

    Thursday, November 20, 2008 1:31 PM
  • User-1005219520 posted

    Why not have just one data model, one set of Primary partial classes (you can add more partial classes to specific sites) - then simply create hard links rather than copies. Any changes made will be instantly reflected in the others. That's what I'm doing right now with 4 web sites ( EF original, EF modified, L2S original, L2S modified) - they all share the same site.master(.cs) - so I can navigate to any of the 4 sites to make comparisons. They all easily share the same DB via the connection string  but I currently have a copy of the EF and L2S data model. I'll move to the hard link approach.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 1:51 PM
  • User1812187139 posted

    Sounds interesting.  I am a little new to the DD so could you expand a little on what you mean by hard links.  Are you talking about multiple sites in a project or multiple projects using the same files.

     

     

    Thursday, November 20, 2008 2:05 PM
  • User-1005219520 posted

    Hard links have nothing to do with DD, they are used in unix and windows (NTFS) to point to a file on the disk. All the files on your disk are hard links. The following commands makes a new hard links pointing to the original file.


    S:\code\DD\EF\L2S>mklink /h site.master  ..\rb\site.master
    Hardlink created for site.master <<===>> ..\rb\site.master

    S:\code\DD\EF\L2S>mklink /h site.master.cs  ..\rb\site.master.cs
    Hardlink created for site.master.cs <<===>> ..\rb\site.master.cs

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 20, 2008 3:35 PM
  • User-1005219520 posted

    I'm using hard links to my data model now and it works fine. Keep in mind if you use hard links for cache-able content (site.master) you will need to disable IIS output caching  if you want to make changes and have the changes shown in the alternate hard linked directories. I have 4 web sites all under one parent, so I disabled user-mode output caching for extension .master.

    Thursday, November 20, 2008 9:21 PM