256 Kilobytes

Answers in Frameworks | By Some Guy


352 views, 0 RAMs, and 1 comment

Tags: Laravel

Profile Photo - Some GuySome GuyBasic Subscriber

Hi! So I'm a bit new to web development, and I just started using Laravel.

Frameworks question here for all you experts (obviously I am not or I wouldn't be asking this Newbie question).

Using Laravel/Eloquent, how do you use the with() method/eager loading for a calculated field? How do I use the with() method/eager loading for a field that's calculated?

Sorry if this question seems basic, but I'm new at this and any help would be appreciated

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 1 year ago 🕓 Posted at 13 January, 2019 04:52 AM PST

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Profile Photo - UnivaUnivaAuthor

Eager loading is achieved using the Include() method.

for example:

LINQ Query Syntax:

using (var context = new SchoolDBEntities())
    var stud1 = (from s in context.Students.Include("Standard")
                where s.StudentName == "Bill"
                select s).FirstOrDefault<Student>();

LINQ Method Syntax:

using (var ctx = new SchoolDBEntities())
    var stud1 = ctx.Students
                   .Where(s => s.StudentName == "Bill")

The above LINQ queries will result in the following SQL query:

[Extent1].[StudentID] AS [StudentID],
[Extent1].[StudentName] AS [StudentName],
[Extent2].[StandardId] AS [StandardId],
[Extent2].[StandardName] AS [StandardName],
[Extent2].[Description] AS [Description]
FROM  [dbo].[Student] AS [Extent1]
LEFT OUTER JOIN [dbo].[Standard] AS [Extent2] ON [Extent1].[StandardId] = [Extent2].[StandardId]
WHERE 'Bill' = [Extent1].[StudentName]

Download more RAM. 🐏 ⨉ 0Posted by Univa 11 months ago 🕓 Posted at 31 May, 2019 11:17 AM PDT


Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!

Read More: