256 Kilobytes

Answers in Frameworks | By Some Guy

Published 5 months agoSun, 13 Jan 2019 04:52:17 -0800

143 views, 0 RAMs, and 1 comment

Tags: Laravel

Profile Photo - Some Guy Some Guy
🗎 3224 🗨 41 🐏 31
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. 🐏 ⨉ 0 Posted by Some Guy 5 months 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 - Univa Univa
🗎 0 🗨 175 🐏 5
Author

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
                   .Include("Standard")
                   .Where(s => s.StudentName == "Bill")
                   .FirstOrDefault<Student>();
}

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

SELECT TOP (1)
[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. 🐏 ⨉ 0 Posted by Univa 3 weeks ago 🕓 Posted at 31 May, 2019 11:17 AM PDT

Hello.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

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
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.