Question: Do we not need to have a USING statment for LINQ to Entites in ASP.NET 5/EF7 anymore?

Question

Do we not need to have a USING statment for LINQ to Entites in ASP.NET 5/EF7 anymore?

Answers 0
Added at 2016-01-14 23:01
Tags
Question

When I worked with Entity Framework 6 in my ASP.Net 4.6 projects I would do build a LINQ to Entities query like this

using (var db = new ForumContext())
{
    var model = db.yaf_Message
                    .Where(yt => yt.yaf_Topic.ForumID == 2 && yt.ReplyTo == null)
                    .Include("yaf_Topic")
                    .OrderByDescending(yt => yt.yaf_Topic.Posted)
                    .Select(yt => new NewsVM()
                    {
                        PostedBy = yt.yaf_Topic.UserDisplayName,
                        RawDatePosted = yt.yaf_Topic.Posted,
                        RawSubject = yt.Message,
                        Title = yt.yaf_Topic.Topic,
                        TopicID = yt.TopicID
                    }).ToList();

    return View(model);
}

I am now working in an ASP.Net 5 (MVC 6) application using Entity Framework 7, to my surprise when I started to write out the LINQ inside my using statement Intellisense did not pick up any table names. So I pulled up an MS Tutorial on doing queries in Entity Framework 7 and found this page. To my surprise they are not making a new instance of the context but they look to be using Dependency Inject to do all the work and they are not calling a USING statement at all.

So do we not need to do a that anymore and DI just takes care of everything for us now?

Answers
Source Show
◀ Wstecz