Dapper Dommel - Usinng Like-queries issue - orm

I'm trying to use Like-queries as shown in Dommel documetation:
using (var con = new SqlConnection())
{
var products = con.Select<Product>(p => p.Name == "Awesome bike");
var products = con.Select<Product>(p => p.Created < new DateTime(2014, 12, 31) && p.InStock > 5);
}
but when i try to execute this piece of code:
using (DbContext ctx = new DbContext())
{
IEnumerable<User> users = ctx.Connection.Select<User>(u => u.UserName.StartsWith("op", StringComparison.InvariantCultureIgnoreCase));
usersBindingSource.DataSource = users.ToList();
}
I'm getting this exeption:
An expression of non-boolean type specified in a context where condition is expected, near '('
I'm using Dommel.1.11.0
Thanks.

The author of Dommel (Henk Mollema) says that StartsWith is only available from version 2.0, currently in beta.

Related

How to query CosmosDb for multiple results using SqlQuerySpec

I'm trying to get multiple documents using a list of numbers. Here's my query
var queryString = "Select * from c Where c.id in (#list)";
var queryParam = new Microsoft.Azure.Documents.SqlParameter("#list", string.Join(",", list.Select(x => $"{x.Id}").ToArray()));
var result = repo.Query(
new SqlQuerySpec()
{
QueryText = queryString,
Parameters = new Microsoft.Azure.Documents.SqlParameterCollection()
{
queryParam
}
}
);
My Query function:
public IQueryable<TClass> Query(SqlQuerySpec sqlQuerySpec = null, bool allowScan = false, int? maxItems = null)
{
var feedOptions = new FeedOptions
{
EnableScanInQuery = allowScan,
MaxItemCount = maxItems,
EnableCrossPartitionQuery = true
};
var querySpec = sqlQuerySpec ?? new SqlQuerySpec();
return sqlQuerySpec != null
? Client.CreateDocumentQuery<TClass>(Collection.DocumentsLink, querySpec, feedOptions)
: Client.CreateDocumentQuery<TClass>(Collection.DocumentsLink, feedOptions);
}
It says there was an error: one of the specified inputs is invalid.
What am I doing wrong?
The id is a string so you would need to wrap each id with single quotes.
This line:
var queryParam = new Microsoft.Azure.Documents.SqlParameter("#list", string.Join(",", list.Select(x => $"{x.Id}").ToArray()));
Should be:
var queryParam = new Microsoft.Azure.Documents.SqlParameter("#list", string.Join(",", list.Select(x => $"'{x.Id}'").ToArray()));

Rally c# task time spent

I have a C# .net application using the rally 3.0.1 API. When I query task in my system I get 0.0 for time spent when I know they have time against them. Anyone know how to get this? Below is my code:
if (uTasks.Count > 0)
{
Request taskRequest = new Request(resultChild["Tasks"]);
QueryResult TaskQueryResult = restApi.Query(taskRequest);
foreach (var items in TaskQueryResult.Results)
//foreach (var items in uTasks)
{
DataRow dtrow2;
dtrow2 = dt.NewRow();
dtrow2["TaskID"]=items["FormattedID"];
dtrow2["Task Name"] = items["Name"];
if (items["Owner"] != null)
{
var owner = items["Owner"];
String ownerref = owner["_ref"];
var ownerFetch = restApi.GetByReference(ownerref, "Name");
string strTemp = ownerFetch["_refObjectName"];
dtrow2["Owner"] = strTemp.Replace(",", " ");
}
\\else { dtrow2["Owner"] = ""; }
dtrow2["Task-Est"] = items["Estimate"];
dtrow2["Task-ToDo"] = items["ToDo"];
dtrow2["Task-Spent"] = items["TimeSpent"];
dtrow2["ObjectType"] = "T";
dt.Rows.Add(dtrow2);
}
}
It seems like that should work. You may want to make sure you're including the TimeSpent field in your fetch before issuing the request.
taskRequest.Fetch = new List<string>() { "TimeSpent" };

error 'Int32 ToInt32(System.String)'

i have added follow action to get products accroding to cat.id.
[HttpPost]
public ActionResult OnlineHome(string CategoryId)
{
OnlineDataModel dm = new OnlineDataModel();
dm.CatagoryData = new List<category>();
dm.ProductData = new List<product>();
dm.CatagoryData = db.categories.ToList();
//dm.ProductData = (from p in db.products where p.CategoryID == Convert.ToInt32(CategoryId) select p).ToList() ;
var data= db.products.Where(d => d.CategoryID == Convert.ToInt32(CategoryId)).ToList();
return View(dm);
}
I am getting following error
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and >this method cannot be translated into a store expression.
need a solution for this.
Solution 1:
Try to declare you Integer variable first:
int iCategoryId = Convert.ToInt32(CategoryId);
Then update your code to:
var data= db.products.Where(d => d.CategoryID == iCategoryId).ToList();
Solution 2 (recommended):
Make sure your action receives an integer and modify the type of the variable:
public ActionResult OnlineHome(int CategoryId)
Then update your code the same way to:
var data = db.products.Where(d => d.CategoryID == CategoryId).ToList();
Feel free to add your own cast validations to both solutions.
Do like this.
int catId = Convert.ToInt32(CategoryId);
var data = db.products.Where(d => d.CategoryID == catId).ToList();

Iterate through collection of List<object>

I have what is probably simple problem, but I am stumped. I call a method from another assembly that returns me a List<object>, this data is Excel spreadsheet data queried using LinqToExcel. Under the scenes, that collection is actually a List<LinqToExcel.Cell>. In LinqToExcel, that makes up a LinqToExcel.Row. I want to be able to bind this data to a Telerik ASP.NET MVC grid for viewing. Here's my controller code:
TypeOfServiceCodeListingDetailViewModel model = new TypeOfServiceCodeListingDetailViewModel();
model.Excel_Data = new List<LinqToExcel.Row>();
using (LinqToExcelReader reader = new LinqToExcelReader(fileName, true))
{
previewData = reader.ReadRawDataByPage(5, 0);
foreach (LinqToExcel.Row item in previewData)
{
model.Excel_Data.Add(item);
}
return View(new GridModel(model.Excel_Data));
}
And in my view:
#(Html.Telerik().Grid(Model.Excel_Data)
.Name("Grid2")
.HtmlAttributes(new { style = "width:400px;" })
.DataBinding(dataBinding => dataBinding.Ajax().Select("GetExcelData", "TypeOfService"))
.Columns(columns =>
{
columns.AutoGenerate(column =>
{
column.Width = "150px";
});
}))
Here's what my grid has headers like the below with no data:
Capacity Count
Thanks for the help!
Here's the code that solved my problem. I'm sure there's a better approach.
using (LinqToExcelReader reader = new LinqToExcelReader(modelDetail.FileName, true))
{
var previewData = reader.ReadRawDataByPage(5, 0);
List<List<string>> masterList = new List<List<string>>();
for (int x = 0; x < previewData.Count; x++)
{
List<string> list = new List<string>();
foreach (var cell in (LinqToExcel.Row)previewData[x])
{
list.Add(cell);
}
masterList.Add(list);
}
var listTest = masterList;
modelDetail.ExcelData = new List<ExcelData>();
foreach (List<string> theList in masterList)
{
ExcelData xlsData = new ExcelData();
xlsData.Column1 = theList[0];
xlsData.Column2 = theList[1];
xlsData.Column3 = theList[2];
xlsData.Column4 = theList[3];
xlsData.Column5 = theList[4];
xlsData.Column6 = theList[5];
xlsData.Column7 = theList[6];
xlsData.Column8 = theList[7];
xlsData.Column9 = theList[8];
xlsData.Column10 = theList[9];
modelDetail.ExcelData.Add(xlsData);
}

Subsonic 3.0 testing - what am I missing here?

EDIT: This issue is already submitted on Github. Changing the "Act" part to this will make the test pass
var result = Adresse.All()
.Where(x => x.AdresseX == txt1 && x.PostBy == txt2)
.FirstOrDefault();
[TestMethod]
public void WTF()
{
//Arrange
string txt1 = "Vingsted Skovvej 1";
string txt2 = "7100 Vejle";
var one = new Adresse { ID = 1, AdresseX = "Vejlevej 55", PostBy = "7300" };
var two = new Adresse {ID = 2, AdresseX = txt1, PostBy = txt2 };
Adresse.Setup(new List<Adresse> { one, two });
//Act
var result = Adresse.SingleOrDefault(x => x.AdresseX == txt1 && x.PostBy == txt2);
//Assert
Assert.AreEqual(2, result.ID);
}
The following test fails me because I get the first object back (the one where ID equals 1)... Can somebody explain to me what I'm doing wrong???
This is logged as an issue on github, it would be worth you adding any info you can to it though.