¿Concatenar varios registros en una cadena para mostrarlo en uno solo? LINQ

General Tech Technology & Software 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

tengo una tabla llamada Technologys y cada Technology puede tener una o mas resolutions. Lo que quiero hacer es que se muestren todas las resoluciones que tiene una tecnologia en un mismo campo.

Ejemplo

Tabla de tecnologias
Nombre   Descripcion   Resoluciones
1        prueba        140,33,32

Necesito hacerlo con linq y me han dicho que la clave esta en un String Join o en un Agregate usando dos querys pero no puedo conseguirlo.

Este es mi codigo:

  var Technology1 = (from  tTechnology in Context.Technology

                                                 join tUsers in Context.Users on tTechnology.EnableBy equals tUsers.UserId into collection
                                                 from subCase in collection.DefaultIfEmpty()
                                                 join tUsers2 in Context.Users on tTechnology.LastChangeBy equals tUsers2.UserId into collection2
                                                 from subCase2 in collection2.DefaultIfEmpty()
                                                 join tUsers3 in Context.Users on tTechnology.DisableBy equals tUsers3.UserId into collection3
                                                 from subCase3 in collection3.DefaultIfEmpty()
                                                 join tResolution in Context.Resolution on tTechnology.TechnologyId equals tResolution.TechnologyId 
                                                 into collection4
                                                 from subCase4 in collection4.DefaultIfEmpty()                  
                                                 where tTechnology.DisableDate == null



                             //orderby 

            select new
            {
                tTechnologyTechnologyId = tTechnology.TechnologyId,
                tTechnologyName = tTechnology.Name,
                tTechnologyDescription = tTechnology.Description,
                tCityName = tTechnology.City.Name,
                tStateName = tTechnology.City.State.Name,
                tCountryName = tTechnology.City.State.Country.Name,
                tResolutions = (from tR in Context.Resolution
                                 where tR.TechnologyId == tTechnology.TechnologyId
                                 select tR.Measure
                               ),

                tEnableBy = (subCase.Name == null ? null : subCase.Name) + "" + (subCase.FirstLastName == null ? null : subCase.FirstLastName) + " " + (subCase.SecondLastName == 
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Deberias usar tTec para acceder a las propiedades

var Technology = (from tTec in Technology1
              select new
              {
                  tTechnologyTechnologyId = tTec.tTechnologyTechnologyId,
                  tTechnologyName = tTec.tTechnologyName,
                  tTechnologyDescription = tTec.tTechnologyDescription,
                  tCityName = tTec.tCityName,
                  tStateName = tTec.tStateName,
                  tCountryName = tTec.tCountryName,
                  tResolutions = String.Join(",", tTec.tResolutions),
              });

Al ser la propiedad Measure del tipo long deberias convertirla en string en la primer query linq

 tResolutions = (from tR in Context.Resolution
                             where tR.TechnologyId == tTechnology.TechnologyId
                             select tR.Measure.ToString()
                           ).ToArray(),

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.