locked
LINQ Guid query example RRS feed

Answers

  • PartitionKey is a string property, by Azure entity definition. In any event, that wasn't the problem. 

    I figured out that you cannot cast IEnumarable<some type> to IEnumerable<object>.  Guess it makes sense since this is how the Generics work in .net 3.5. However, it certainly makes class inheritance less interesting.

     

     

     

    Wednesday, December 15, 2010 2:28 PM

All replies

  • You can do LINQ queries against entities with Guid members the same way as any other datatype. There's no difference in syntax...  ...the underlying corresponding data type in SQL Azure and SQL Server is uniqueidentifier.

     


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    Tuesday, December 14, 2010 3:23 AM
  • Hi

     

    Can't seem to get this to work. I'm using StorageClient. The query seems well formed - the data is certainly there in the table but the query never retrieves anything.

     

    Query generation code snippet:

    BodyCloudContext context = GetQueryContext(new Body()) as BodyCloudContext;

                if (context != null)

                {

     

                    IQueryable<Body> q = this.GetQuery(ref context);

                    CloudTableQuery<Body> tq = TableServiceExtensionMethods.AsTableServiceQuery<Body>(q);

                    return context.RetrieveEntities(tq) as IEnumerable<object>;

                }

                else

                {

                    return null; //empty list

                }

    q and tq both look like this: https://[storename].table.core.windows.net/Body()?$filter=(ProxyIdentifier eq guid'ec4f6db8-17e8-4d7a-9852-7ca9109c1c59') and (PartitionKey eq '53b867dc-8f2a-4dd2-aa3f-19cb823954e2')

     

    Those values are in the table. 

    However, the RetrieveEntities() call (which just does query.Execute() returning IEnumerable) always returns null.

     

    What gives?

     

     

     

     

    Tuesday, December 14, 2010 4:30 PM
  • Hi,

    This query seems not right

    https://[storename].table.core.windows.net/Body()?$filter=(ProxyIdentifier eq guid'ec4f6db8-17e8-4d7a-9852-7ca9109c1c59') and (PartitionKey eq '53b867dc-8f2a-4dd2-aa3f-19cb823954e2')

    if the partitionKey is of GUID type, then it the query may like this

    https://[storename].table.core.windows.net/Body()?$filter=(ProxyIdentifier eq guid'ec4f6db8-17e8-4d7a-9852-7ca9109c1c59') and (PartitionKey eq guid'53b867dc-8f2a-4dd2-aa3f-19cb823954e2')

    Thanks,


    Mog Liang
    Wednesday, December 15, 2010 3:38 AM
  • PartitionKey is a string property, by Azure entity definition. In any event, that wasn't the problem. 

    I figured out that you cannot cast IEnumarable<some type> to IEnumerable<object>.  Guess it makes sense since this is how the Generics work in .net 3.5. However, it certainly makes class inheritance less interesting.

     

     

     

    Wednesday, December 15, 2010 2:28 PM
  • I figured out that you cannot cast IEnumarable<some type> to IEnumerable<object>.  Guess it makes sense since this is how the Generics work in .net 3.5. However, it certainly makes class inheritance less interesting.

     

    IEnumerable<T> has a Cast<T> method that you can use for casting the members of an enumeration...

    E.g.:
    List<someType> someList = new List<someType>();
    IEnumerable<object> objects = someList.Cast<object>();

     


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Visual Studio add-in with loads of new features for the Entity Framework and Linq-to-SQL designers
     huagati.com/L2SProfiler - Runtime SQL query profiler for Linq-to-SQL and Entity Framework v4
    Thursday, December 16, 2010 2:47 AM