c# - Where does the .ToList() go in LINQ query result -
when getting data populate data grid, have pulled data, made list , mapped model, this:
public list<person> getpeople() { var data = _db.person.tolist(); list<person> people = new list<person>(); foreach (var item in data) { person person = new person() { personid = item.personid, firstname = item.firstname, lastname = item.lastname }; people.add(person); } return people; } this works fine, in interest of writing less code discovered .select method , (what think is) anonymous type. have:
public list<person> getpeople() { return _db.person.select(d => new person { personid = item.personid, firstname = item.firstname, lastname = item.lastname }).tolist(); } though not easy read, works fine too. there preference either way?
the second preferred in cases. main differences are:
- the second example turn projection sql statement, returning columns ask for.
- the first example creates 2 lists, 1 of temporary , eligible garbage collection relatively quickly. may issue if
peopletable large.
note if did not have tolist() after _db.person 2 methods virtually identical.
and not creating anonymous type since specify type (person). create anonymous type have new {... properties ...}
though not easy read,
i think once used linq statements select you'll find very easy read.
Thanks, so fascinating! To read how you talked about the importance of skills in backend developer jobs. Choosing the right platform that gets you a good authentic work experience and showcases your skills in the right manner is very important. Eiliana.com is one of the best freelancing platforms you can connect with.
ReplyDeleteAgencies are also concentrating their efforts on world777 gaming, which is expected to be worth $300 billion by 2022. India accounts just a fragment of this, with a market share of about 1%. Given that Indian gambling companies spent Rs 1400 crore on advertising in 2021 alone, the figure is nothing to sneeze at.
ReplyDeletePeer recovery support programs in Illinois connect individuals with trained peers who have lived recovery experience. These programs foster trust, hope, and accountability while offering mentorship, encouragement, and practical support to help individuals successfully navigate recovery journeys and maintain sobriety within their communities.
ReplyDeleteInner Child Healing Austin focuses on resolving emotional wounds and reconnecting with your authentic self. Through compassionate therapeutic techniques, clients heal past trauma, release limiting beliefs, and cultivate self-love, emotional resilience, and personal empowerment in a safe and nurturing environment.
ReplyDeleteOur food assistance for vulnerable children ensures no child goes to bed hungry. Through school meals and community programs, food assistance for vulnerable children promotes health, growth, and brighter futures for those facing poverty and crisis situations.
ReplyDeleteHair Restoration in Denville, NJ offers innovative treatments to combat thinning hair and hair loss. Our customized solutions stimulate natural growth, strengthen follicles, and improve scalp health. Restore thicker, fuller hair with advanced therapies designed for both men and women seeking long-term results.
ReplyDeleteGain clarity through Planetary transit insights that reveal how current cosmic movements influence your life. Understand cycles of growth, challenge, and opportunity with detailed transit analysis. Planetary transit insights help you navigate timing, decisions, and personal evolution with confidence and awareness.
ReplyDeleteEmpowerment coaching for health recovery supports your physical and emotional healing journey. We combine education, mindset strategies, and personalized action plans to help you regain strength and resilience. Feel supported, motivated, and confident as you navigate recovery with clarity and purpose.
ReplyDeleteinsulated concrete form suppliers US deliver innovative building systems that combine insulation and structural integrity. Our solutions help reduce energy bills, improve comfort, and speed construction timelines. With reliable supply, technical support, and nationwide distribution, we help contractors and homeowners build stronger, safer, and more efficient structures with lasting performance.
ReplyDeleteOur Overnight dog care for friendly pups in Northeast Albuquerque ensures safe social play and restful sleep. Paws Playland ABQ provides supervised interaction, cozy bedding, and personalized routines so your pup feels comfortable, secure, and cared for during every overnight stay.
ReplyDeleteOur Mental wellness support services focus on strengthening emotional resilience, improving self-awareness, and promoting overall psychological health. We help individuals manage daily stressors, build coping skills, and maintain balance in work and relationships. Personalized mental wellness support ensures ongoing growth, stability, and confidence.
ReplyDeleteFunctional lab testing Weatherford TX provides deeper insight into hormones, metabolism, gut health, and inflammation. Our advanced testing identifies underlying concerns early, allowing personalized treatment plans that improve energy, resilience, and overall health through data-driven functional medicine strategies.
ReplyDeleteOur Certified Marketing Solutions are designed to deliver measurable results through strategic planning and execution. We use industry-approved tools, expert methodologies, and performance-focused campaigns to enhance brand presence. From digital advertising to conversion optimization, we ensure businesses achieve higher ROI and long-term marketing success.
ReplyDeleteOur Certified Marketing Solutions ensure reliable, professional strategies backed by industry expertise. We help businesses grow with proven digital marketing methods, performance tracking, and optimized campaigns designed to increase traffic, strengthen brand credibility, and improve conversion rates.
ReplyDeleteDelivering Certified Marketing Solutions designed to strengthen brand positioning, accelerate customer acquisition, and improve online visibility. Our experienced strategists combine research, automation, and creative execution to craft campaigns that generate consistent leads, measurable growth, and lasting business impact globally today.
ReplyDelete