Permalink
Browse files

fixed small problem with LINQ to Cassandra

  • Loading branch information...
1 parent fc725a6 commit 4f46cb4b7d0153e6a4a4b98f4e8823247e578ba6 @nberardi nberardi committed Feb 11, 2012
View
3 src/Linq/CassandraColumnFamily+QueryProvider.cs
@@ -129,6 +129,9 @@ TResult IQueryProvider.Execute<TResult>(Expression expression)
if (!typeof(TResult).IsAssignableFrom(typeof(ICqlRow)))
throw new CassandraException("'TElement' must inherit from IFluentBaseColumnFamily");
+ if (expression.NodeType == ExpressionType.Call)
+ expression = ((MethodCallExpression)expression).Arguments[0];
+
var result = new CqlQuery(expression, this);
return (TResult)Enumerable.FirstOrDefault(result);
}
View
2 src/Linq/CqlQueryEvaluator.cs
@@ -202,8 +202,6 @@ private void VisitMethodCall(MethodCallExpression exp)
AddCriteria(exp.Arguments[1]);
else if (exp.Method.Name == "Select")
AddField(SimplifyExpression(exp.Arguments[1]));
- else if (exp.Method.Name.StartsWith("First"))
- FirstCount = "1";
else
throw new NotSupportedException("Method call to " + exp.Method.Name + " is not supported.");
}
View
8 src/Operations/ExecuteCqlQuery.cs
@@ -26,10 +26,12 @@ private CassandraColumnFamilySchema TryGetSchema(Apache.Cassandra.CqlResult resu
var keyName = CassandraColumnFamilySchema.DefaultKeyName.ToBigEndian();
var resultSchema = result.Schema;
var colNameType = CassandraObject.ParseType(resultSchema.Default_name_type);
+ var colValueType = CassandraObject.ParseType(resultSchema.Default_value_type);
var schema = new CassandraColumnFamilySchema();
schema.FamilyName = familyName;
schema.ColumnNameType = colNameType;
+ schema.DefaultColumnValueType = colValueType;
foreach (var s in resultSchema.Value_types)
{
@@ -99,11 +101,7 @@ private IEnumerable<FluentColumn> GetColumns(Apache.Cassandra.CqlRow row, Cassan
if (col.Timestamp == -1)
continue;
-
- var colSchema = schema.Columns.Where(x => x.Name == col.Name).FirstOrDefault();
- var fcol = Helper.ConvertColumnToFluentColumn(col);
- fcol.SetSchema(colSchema);
-
+ var fcol = Helper.ConvertColumnToFluentColumn(col, schema);
yield return fcol;
}
}
View
10 test/FluentCassandra.Sandbox/Program.cs
@@ -28,14 +28,15 @@ private static void SetupKeyspace()
keyspace.TryCreateSelf();
db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Posts (
- KEY blob PRIMARY KEY,
+ KEY text PRIMARY KEY,
Title text,
Body text,
Author text,
PostedOn timestamp
);");
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "Tags",
+ KeyType = CassandraType.UTF8Type,
ColumnNameType = CassandraType.Int32Type,
DefaultColumnValueType = CassandraType.UTF8Type
});
@@ -117,7 +118,10 @@ private static void ReadPost()
// get the post back from the database
ConsoleHeader("getting 'first-blog-post'");
dynamic post = postFamily.Get(key).FirstOrDefault();
- dynamic tags = tagsFamily.Get(key).FirstOrDefault();
+ dynamic tags = (
+ from t in tagsFamily
+ where t.Key == key
+ select t).FirstOrDefault();
// show details
ConsoleHeader("showing post");
@@ -131,7 +135,7 @@ private static void ReadPost()
// show tags
ConsoleHeader("showing tags");
foreach (var tag in tags)
- Console.WriteLine(String.Format("{0}:{1},", tag.ColumnName, tag.ColumnValue));
+ Console.WriteLine(String.Format("{0}:{1}", tag.ColumnName, tag.ColumnValue));
}
}

0 comments on commit 4f46cb4

Please sign in to comment.