none
Design question about ORM and EF RRS feed

  • General discussion

  • Hello All

    I'm using ASP.NET MVC 4 + MS SQL 2008 + EF5 to develop website. I'm using Database first approach. But I'm little bit confused with default mappings created in Visual Studio designer from my database. I'd like to know where to implement read/store logic.

    I have several options:

    1) use default model, generated automatically and code everything about reading/storing entites in MVC. This is wirst case

    2) Rewrite mappings, tried already, for me it's like black box compared MS Access and SQL Views

    3) Use SQL Views instead of tables, but this way requires me to write store procedures to handle store logic (because view uses several tables and it's create restriction to only select queries)

    I'm personally thinking that it should be possible to use second way, but almost everywhere in Internet I found only CodeFirst examples, which is not appropriate for me. If needed I can describe tables structure


    MCSE 2003: Messaging, Security
    MCITP: Server Administrator, Enterprise Administrator, Virtualization Administrator
    MCITP: Consumer Desktop Support, Enterprise Desktop Support, Enterprise Desktop Support Windows 7, Enterprise Desktop Administrator
    SMS/SCCM, ISA 2004/2006, CCNA Security

    Tuesday, February 5, 2013 10:58 AM

All replies

  • Hi,

    What kind of read/store logic do you want? Could you please provide an example?

    In addition, please check if this article helps: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

    Wednesday, February 6, 2013 6:02 AM
  • On 2/5/2013 5:58 AM, Sergey Sypalo wrote:
     
    <snipped>
     
    If you are using N-Tier in an ASP.NET solution, then you should leave
    those EF entities at the DAL and send DTO(s) (Data Transfer Objects) to
    the UI. You map the data between the two objects.
     
    Wednesday, February 6, 2013 12:22 PM
  • Hi SilentJealousy, I have two tables Words:
    WordID int
    WordText nvarchar(50)
    WordLang varchar(2)

    Translations:
    OrigWordID int => FK to Words.WordID
    TransWordID int => FK to Words.WordID

    Functionality that i need:
    Be able to read list of words from particular language
    Be able to read and write list of words and it's translations
    First requirement is quite easy, while second requires explanation
    I've created a SQL view, which shows me table with two columns with required languages. But to store data in a view with more than one table I need to write stored procedure and import it as well to MVC project. Another assumption i've tried when started to read about hierarchy inheritance and mapping. I tought that's it's possible to specify correct mappings and EF will do all work for me. With a SQL view i'm working with strings (WordText) and not identifiers, so each time when I need to scaffold it requires less time for HTML editing. With repositories I need to move all logic from stored procedures to repositity itself and call appropriate method for reading and storing data as I understand. But repository sill using some model to understand what kind of tables in database, so for me it's not clear how to use repositories and database first approach. Do i need EDMX model or not, if you have any links I would appreciate

    MCSE 2003: Messaging, Security
    MCITP: Server Administrator, Enterprise Administrator, Virtualization Administrator
    MCITP: Consumer Desktop Support, Enterprise Desktop Support, Enterprise Desktop Support Windows 7, Enterprise Desktop Administrator
    SMS/SCCM, ISA 2004/2006, CCNA Security

    Wednesday, February 6, 2013 4:39 PM