This is a migrated thread and some comments may be shown as answers.

Linq query problem related to return type

3 Answers 66 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
kunal
Top achievements
Rank 1
kunal asked on 10 Sep 2010, 10:35 AM
What will be the Retrun type of Following function 
Because i want All record from both table........ and i want to apply foreach loop on list
Can AnyBody help me out
public static ?????? AttributeListByType(SMDSCommon.AttributeOftype objAttributeOftype, IObjectScope objScope)
    {
        var data = from aAttribute in objScope.Extent<SMDS.DataAccess.Attribute>()
                   from aAttributeContentType in objScope.Extent<AttributeContentType>()
                   where
                    aAttribute.Id == aAttributeContentType.AttributeId
                    && aAttribute.DeleteFlag == (sbyte)SMDSCommon.Delete.No
                    && aAttribute.IsActive == (sbyte)SMDSCommon.Delete.Yes
                    && aAttribute.IsApproved == (sbyte)SMDSCommon.Delete.Yes
                    && aAttribute.AttributeOfType == objAttributeOftype.ToString()
                   orderby aAttribute.FieldOrder ascending

                    select new
                    {
                        aAttribute,aAttributeContentType
                    };

        return data;
    }

3 Answers, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 10 Sep 2010, 12:38 PM
Hello kunal,

 ?????? will be an anonymous type as it is specified in this way with your LINQ query.
Use 
  .... select new MyTypeName { attr = aAttribute, typ = aAttributeContentType }

so specify the name of the type that is to be used.

Greetings,
Thomas
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
kunal
Top achievements
Rank 1
answered on 10 Sep 2010, 01:12 PM
hi
I don't get u'r answer
please give me one example..........
waiting for u'r replay......................................................................

 

0
Thomas
Telerik team
answered on 10 Sep 2010, 02:43 PM
Hi kunal,

 an anonymous type is a type that the compiler creates for you and which therefore does not have a stable name (the compiler is free to choose any name it wants at any compile time). Therefore nobody on this planet can say which type you will get for ??????.

To avoid this, use a projection to a type that you define:

public class MyType
{
    SMDS.DataAccess.Attribute A { get; set; }
    AttributeContentType T { get; set; }
}
 
public static System.Linq.IQueryable<MyType> AttributeListByType(SMDSCommon.AttributeOftype objAttributeOftype, IObjectScope objScope)
{
    var data = from aAttribute in objScope.Extent<SMDS.DataAccess.Attribute>()
               from aAttributeContentType in objScope.Extent<AttributeContentType>()
               where
                aAttribute.Id == aAttributeContentType.AttributeId
                && aAttribute.DeleteFlag == (sbyte)SMDSCommon.Delete.No
                && aAttribute.IsActive == (sbyte)SMDSCommon.Delete.Yes
                && aAttribute.IsApproved == (sbyte)SMDSCommon.Delete.Yes
                && aAttribute.AttributeOfType == objAttributeOftype.ToString()
               orderby aAttribute.FieldOrder ascending
               select new MyType
               {
                     A = aAttribute,
                     T = aAttributeContentType
               };
  
    return data;
}

Hope this helps,
Thomas
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
LINQ (LINQ specific questions)
Asked by
kunal
Top achievements
Rank 1
Answers by
Thomas
Telerik team
kunal
Top achievements
Rank 1
Share this question
or