Nassif Nassif - 5 months ago 59
C# Question

C# entity framework using LINQ

I have a job interview tomorrow and they stated that i have an exam about "C# development using entity framework and LINQ".

For me, entity framework and LINQ are two new approaches. I already know to build C# application where i'd connect the app to a SQLServer database, using the normal connection strings and SQL syntax.

When researching about Entity framework, as a start i learned that i can use the SQLServer object explorer, and create a local database easily from visual studio, then add an entity model and perform changes easily.
As an example, you can see the following code below used to insert a student in a student list.

using (SchoolEntities1 context = new SchoolEntities1())
StudentList sl = new StudentList
Name = tb_Name.Text,
Gender = cb_Gender.Text,
Grade = Convert.ToInt32(tb_Grade.Text)


Is this the basic function of entity framework? Should i study anything else that might be useful (other than database manipulation INSERT/UPDATE/DELETE/SELECT)?

Additionally for the LINQ, when researching about it, i see different types of coding as an example, is the definition of student list in the code above a LINQ function? Do i have to use lambda expressions in my codes?

Any links that can help me in this small time frame would be appreciated.



There are 3 kinds of EF approaches.Those are:

  1. Model First
  2. Database First
  3. Code First

Here you can find out basics of EF: Entity Framework Basics

There are 2 types of query methods.Those are:

1. Query based

e.g : Projection

IQueryable<Product> productsQuery = from product in context.Products
                                        select product;

2. Method based

e.g : Projection

 var query = context.Products
        .Select(product => new
            ProductId = product.ProductID,
            ProductName = product.Name

Here you can see this: Queries in LINQ to Entities

You can find out more at Entity Framework Interview Questions and Answers

Good Luck to you ! :)