2

I had a conceptual question about EF.

I am pretty new to the idea of an ORM in general, so I wanted to get some clarification on somethings:

  • I have an existing database, and I want to convert the data I am pulling from that data into objects that my application can interact with as objects, rather than just data.

An ORM will accomplish that, correct?

  • In EF can I create methods specific to my objects? For instance, can I make it so my application can call something like employee.ViewDetails() Where employee is an object? If so, is there a simple tutorial you could recommend?

  • Is EF portable between applications? Meaning, is it easy to build an EF structure and then port it to multiple applications? I can just do that by referencing it from different solutions, no?

Thanks for all the help

Iglesk
  • 1,131
  • 1
  • 11
  • 14
blubberbo
  • 4,441
  • 4
  • 23
  • 36

2 Answers2

3

Before Answering your Question let me give you short brief about Entity Framework

Using the Entity Framework to write data-oriented applications provides the following benefits:

  • Reduced development time: the framework provides the core data access capabilities so developers can concentrate on application logic.

  • Developers can work in terms of a more application-centric object model, including types with inheritance, complex members, and relationships. In .NET Framework 4, the Entity Framework also supports Persistence Ignorance through Plain Old CLR Objects (POCO) entities.

  • Applications are freed from hard-coded dependencies on a particular data engine or storage schema by supporting a conceptual model that is independent of the physical/storage model.

  • Mappings between the object model and the storage-specific schema can change without changing the application code.
  • Language-Integrated Query support (called LINQ to Entities) provides IntelliSense and compile-time syntax validation for writing queries against a conceptual model.

enter image description here

Going Back to your first Question

  • Yes

Entity framework is useful in three scenarios.

1- First, if you already have existing database or you want to design your database ahead of other parts of the application. (Which is your current case)

2- Second, you want to focus on your domain classes and then create the database from your domain classes.

3- Third, you want to design your database schema on the visual designer and then create the database and classes.

The following figure illustrates the above scenarios.


2) in EF can I create methods specific to my objects? For instance, can I make it so my application can call something like employee.ViewDetails() where an employee is an object? If so, is there a simple tutorial you could recommend?

Yes Sure Take a look on this: - https://msdn.microsoft.com/en-us/library/dd456847.aspx - http://www.asp.net/mvc/overview/older-versions-1/models-data/creating-model-classes-with-the-entity-framework-cs


3) Is EF portable between applications? Meaning, is it easy to build an EF structure and then port it to multiple applications? I can just do that by referencing it from different solutions?

you might need to Implementing the Repository Patterns Have a look at this Amazing tutorial

Hope this helps! Wish you the best :)

Iglesk
  • 1,131
  • 1
  • 11
  • 14
0

Blubberbo,

There are various ways to work with EF, they are Code First, Model First and Database first. More information can be found in the below SO post.

Code-first vs Model/Database-first

1) You can use LINQ to SQL or LINQ Objects in context with an ORM like EF to interact with Objects.

2) If you would like methods specific to specific types, then you might want to take a look at writing extension methods for specific types. More information here https://msdn.microsoft.com/en-us/library/bb311042.aspx

3) To make it portable, you might want to build abstractions around it, like for example you might want to write repository classes to separate the DB layer that uses EF and the layer that calls it(a.k.a the repository layer). More info can be found here

http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

Hope that helps,

Praveen Raju

Community
  • 1
  • 1
Praveen
  • 1
  • 2
  • thanks for the answer. to clarify - repository classes make it more portable but then allowing you to bring those repository classes into other projects and not have to worry about db connections or anything, because those are defined in the projects themselves and the repository is one step above that, correct? Then it's just a matter of referencing the same repositories from different projects? – blubberbo Jun 22 '16 at 20:31