Linq query problem related to return type

4 posts, 0 answers
  1. kunal
    kunal avatar
    11 posts
    Member since:
    Jan 2009

    Posted 10 Sep 2010 Link to this post

    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;
        }
    
    
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 10 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. kunal
    kunal avatar
    11 posts
    Member since:
    Jan 2009

    Posted 10 Sep 2010 Link to this post

    hi
    I don't get u'r answer
    please give me one example..........
    waiting for u'r replay......................................................................

     

  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 10 Sep 2010 Link to this post

    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
Back to Top