Getting Function Evaluation Timedout error when using function inside linq query - c#

Thanks in advance.
I am trying to query an object and create anonymous type from the result. I am using a function inside the linq query. At this stage i am getting an error saying "Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function..."
Please find below my sample code.
var serviceResult = _service.GeResponse(panId, numberOfTransactions, startDate, endDate);
var balanceTrans = GetAllTypes<BalanceAdjustment>(serviceResult);
var presentmentTrans = GetAllTypes<Presentment>(serviceResult);
var test = balanceTrans.AsEnumerable();
var obj = test.Select(item => new SearchCardTransactionResult
{
PanId = item.PanId,
CardNumber = item.CardNumberFormatted,
Balance = item.FinancialBalance,
BillingAmount = Math.Abs(item.BillingAmount).Format(),
BillingCurrency = GetCurrencyCode(item.BillingCurrency)
});
private IList<T> GetAllTypes<T>(GetTransactionsResponse result)
where T : ValitorServices.ValitorPanWS.AbstractFinancialTransaction
{
return result.FinanacialTransactions.OfType<T>().ToList();
}
Could anyone advice what am i doing wrong here?
Many Thanks

I managed to resolve by using the following code.
var currencyCodes = _service.GetCurrencyCodes().ToList();
var test = balanceTrans.AsEnumerable();
var obj = test.AsEnumerable().Select(item => new SearchCardTransactionResult
{
PanId = item.PanId,
CardNumber = item.CardNumberFormatted,
Balance = item.FinancialBalance,
BillingAmount = Math.Abs(item.BillingAmount).Format(),
BillingCurrency = currencyCodes.First(c=>c.NumericCode.Equals(item.BillingCurrency)).AlphabeticCode
});

Related

Must declare the scalar variable - Dapper

I do multiple mapping on the dapper. Then I try to implement dapper builder
But the it return exception:
Must declare the scalar variable \"#ExecutionId\".\r\nInvalid usage of the option NEXT in the FETCH statement.
Without multiple mapping, never give a problem
Here my snippet code
var Builder = new SqlBuilder();
var SelectedQuery = Builder.AddTemplate(# "SELECT e.[Id], e.[BuyOrderBookId], e.[SellOrderBookId], e.[Volume], e.[Price], e.[CreationDate], e.[StatusId], bo.[UserId], bo.[MarketId], so.[UserId] FROM[dbo].[Execution] AS e JOIN[dbo].[OrderBook] AS bo ON e.BuyOrderBookId = bo.Id JOIN[dbo].[OrderBook] as so ON e.SellOrderBookId = so.Id
/**where**/
ORDER BY e.[CreationDate] DESC OFFSET #skip ROWS FETCH NEXT #take ROWS ONLY;
");
//Execution ID
if (filter.ExecutionId.HasValue)
Builder.Where("e.[Id] = #ExecutionId", new {ExecutionId = filter.ExecutionId.Value
});
var query = await connection.QueryAsync < ExecutionViewModel, OrderBookViewModel, OrderBookViewModel, ExecutionViewModel > (SelectedQuery.RawSql, (execute, buyOrder, sellOrder) => {
execute.BuyUserId = buyOrder.UserId;
execute.SellUserId = sellOrder.UserId;
execute.MarketId = buyOrder.MarketId;
return execute;
},
splitOn: "UserId,UserId",
param: new {
SelectedQuery.Parameters,
skip = (pagingParam.PageNumber - 1) * pagingParam.PageSize,
take = pagingParam.PageSize
});
Anyone know did I do something wrong here?
Update
I just fix like this
if (filter.ExecutionId.HasValue)
Builder.Where(String.Format("e.[Id] = {0}",filter.ExecutionId));
I believe this is not good way to implement. Is risk sql injection.
Try changing the where clause like this:
if (filter.ExecutionId.HasValue)
Builder.Where("e.[Id]", new {Id = filter.ExecutionId.Value});
You can add parameters like this.
if (filter.ExecutionId.HasValue)
{
Builder.Where("e.[Id] = #ExecutionId");
((DynamicParameters)SelectedQuery.Parameters)
.AddDynamicParams(new {
ExecutionId = filter.ExecutionId.Value
});
}

assigning value from select linq query not updating the list

query is like this:-
labRequestItem.LabTest.Select(p=>p.LabTestICDCodes= labRequests.ICDCodes.Select(t => new ICDCodeList()
{
ICDCodeId = t.ICDCodeId,
ICDCode = t.ICDCodeName,
ICDDescription = t.ICDDescription,
ICDCodeType = t.ICDCodeType
}).ToArray());
Now the issue is that LabTestICDCodes is not updating with the new list value returning from select statement
I have tested in the Linqpad, following shall work, but please note:
finalResult would be List of type of LabTestICDCodes (which is again IEnumerable itself) with new / modified values, as that's the only column projected. You have to project the whole object you want as a result, values will modify as expected
var finalResult =
labRequestItem.LabTest.Select(p=>p.LabTestICDCodes= labRequests.ICDCodes.Select(t => new ICDCodeList()
{
ICDCodeId = t.ICDCodeId,
ICDCode = t.ICDCodeName,
ICDDescription = t.ICDDescription,
ICDCodeType = t.ICDCodeType
}).ToArray()).ToList();
I found only way to solve this problem by doing following step:-
1.Get the value in local variable
var icdList = labRequests.ICDCodes.Select(t => new ICDCodeList()
{
ICDCodeId = t.ICDCodeId,
ICDCode = t.ICDCodeName,
ICDDescription = t.ICDDescription,
ICDCodeType = t.ICDCodeType
}).ToArray();
Now assign the value by usinf foreach loop.
foreach (var test in labRequestItem.LabTest)
{
test.LabTestICDCodes = icdList;
}
In Last step I have to use foreach loop, if any other solution then
please reply otherwise I will use the same as it mentioned above.

redis c# client, how do i get Subscribers count?

i need to give statistic about my publisher app
like how many subscribers are there?
i cant seen to get that information from the redis server
i already tried to find in the 'ServiceStack.Redis.RedisSubscription'
i found this:
var channel = ConfigurationManager.AppSettings["redis_channel"];
var _redisClient = new RedisClient("localhost", 6379);
var subscription = _redisClient.CreateSubscription();
//subscription.SubscribeToChannels(channel);
var subscription_count = (int)subscription.SubscriptionCount
but it returning 0 every time.
any ideas?
edit:
i found this http://redis.io/commands/client-list
but steel need some help on how to use it
thanks : )
i got it!
if anyone need that's i did:
var redis_ip = ConfigurationManager.AppSettings["redis_server_ip"];
var redis_port = ConfigurationManager.AppSettings["redis_server_port"];
int redis_port_int = 0;
if (!int.TryParse(redis_port, out redis_port_int))
{
redis_port_int = 6739;
}
RedisNativeClient rnClient = new RedisNativeClient(redis_ip, redis_port_int);
var clientlist_byte = rnClient.ClientList();
var clientlist_string = Encoding.UTF8.GetString(clientlist_byte);
var clientamount_double = clientlist_string.Split("\n".ToCharArray()).Length;
var clientlist_int = (clientamount_double/2) - 1;
return clientlist_int;
the '-1' is to remove my selt from the count,
the /2 it's because after the split i get a doubled amount

Having trouble with a very basic search -- no results

I have Elasticsearch up and running. Using Sense within Marvel, I am able to get a result, with this query:
GET _search
{
"query": {
"query_string": {
"query": "massa"
}
}
}
My c# code, trying to recreate the above:
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node).SetDefaultIndex("mediaitems");
var client = new ElasticClient(settings);
var results = client.Search<stuff>(s => s
.Query(qs => qs.QueryString(q => q.Query("massa"))));
var d = results.Documents;
But unfortunately I'm not getting any results, nothing in "results.Documents". Any suggestions? Maybe a way to see the generated json? What is the simplest way to just query everything in an index? Thanks!
Even though your search results are going to be mapped to the proper type because you are using .Search<stuff>, you still need to set the default type as part of your query.
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node).SetDefaultIndex("mediaitems");
var client = new ElasticClient(settings);
var results = client.Search<stuff>(s => s
.Type("stuff") //or .Type(typeof(stuff)) if you have decorated your stuff class correctly.
.Query(qs => qs.QueryString(q => q.Query("massa"))));
var d = results.Documents;
Additionally, your results response contains a ConnectionStatus property. You can interrogate this property to see the Request and Response to/from Elasticsearch to see if your query is being executed as you expect.
Update: You can also set a default type the index settings as well.
var settings = new ConnectionSettings(node).SetDefualtIndex("mediaitems");
settings.MapDefaultTypeIndices(d=>d.Add(typeof(stuff), "mediaitems");
You can also check nest raw client
var results = client.Raw.SearchPost("mediaitems", "stuff", new
{
query = new
{
query_string = new
{
query = "massa"
}
}
});
You can get the values of search request URL and JSON request body as under:
var requestURL = response.RequestInformation.RequestUrl;
var jsonBody = Encoding.UTF8.GetString(response.RequestInformation.Request);
You can find other useful properties in RequestInformation for debugging.

How do i check if my Linq query produced any result?

Hi guys I am using entity framework, I am facing some problem while checking if my linq returned any results, if it returns any result I want to use it as a data source, the following is the code please have a look:
var dbContext = new DBEntities();
try
{
var linQuery = from cq in dbContext.tblCharacteristics
where cq.CharacteristicID.Equals(combobox1.SelectedText)
select new
{
CharacteristicIDs = cq.CharID,
CharacteristicNames = cq.CharName
};
if (linQuery.Any()) //Also tried with linQuery.Count() != 0
{
lbChaKeyValues.DataSource = linQuery;
lbChaKeyValues.DisplayMember = "CharacteristicNames";
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dbContext.Dispose();
}
I am getting following error : "DbComparisonExpression requires arguments with comparable types."
IF CharacteristicID is an integer type, the comparison won't work. Instead try
var inputFromUser = Int32.Parse( combobox1.SelectedText );
var linQuery = from cq in dbContext.tblCharacteristics
where cq.CharacteristicID == inputFromUser
select new
{
CharacteristicIDs = cq.CharID,
CharacteristicNames = cq.CharName
};
Incidentally .Any() is the correct way to test for search results. And if you're not going to use the return results, there's no need to project the data into an anonymous type. Just use select true or select cq which allows the optimizer to use the best index in the DB.

Categories

Resources