SPMetal with class. How to retrieve lookup columns

I am using SPmetal to read through multiple lists.

I am using Linq to retrieve list items, one of the column is lookup from other list. How to retrieve the lookup column using l

June 23rd, 2015 7:08am

Hi,

If we consider this example as your query:

var LinqExample = (from testData in LINQObject.ListName
		   where testData.ColumnName!= null 
                   select testData).FirstOrDefault();

you can get your Lookup column data like this:

if (LinqExample!= null)
{
string LookupData = LinqExample.LookupColumnNameDestList.LookupColumnNameSourceList.ToString();
}

Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 7:55am

you can also get similar example here:

https://msdn.microsoft.com/en-us/library/ff798478.aspx?f=255&MSPPError=-2147217396

 
June 23rd, 2015 8:11am

none of the links shows how to handle multi choice look up column
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2015 11:45pm

Hi,

     As per my understanding, you are trying to get values of multi value lookup column. Check this link:

https://social.msdn.microsoft.com/Forums/office/en-US/2dd9d328-f42b-42bb-8575-be8dea1d02d9/linq-to-sharepoint-joins-on-multivalue-lookup-field?forum=sharepointdevelopmentprevious

June 24th, 2015 12:47am

Example this s the code I have

var myQ = from fList in FirstEtity
        select new
            {
                fList.Title,
    fList.Hobby // This Hobby has multiple value. And its a look up column
   }

I am unable to get the data for  "fList.Hobby "

it always throws error.

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 2:40am

Example this s the code I have

var myQ = from fList in FirstEtity
        select new
            {
                fList.Title,
    fList.Hobby // This Hobby has multiple value. And its a look up column
   }

I am unable to get the data for  "fList.Hobby "

it always throws error.

Error "The query uses unsupported elements, such as references to more than one list, or the projection of a complete entity by using EntityRef/EntitySet."

June 24th, 2015 6:38am

Found the solution the following code helps

var myQ = from fList in FirstEtity
        select new
            {
                fList.Title,
				//fList.Hobby // This Hobby has multiple value. And its a look up column
				 Hobby = (from aHobby in fList.Hobby.AsEnumerable()
					 select new
					 {
						aHobby.Title
					 }),
			}

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 11:44pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics