Hi I have this code working when searching a string I just use .contains but
what will I use if I will search Date?
if (!String.IsNullOrEmpty(id))
{
domescticwastes = domescticwastes.Where
(s => s.Location.Contains(id) ||
s.Name.Contains(id) ||
s.Address.Contains(id) ||
s.Contact.Contains(id) ||
s.AccNo.Contains(id) ||
s.Contractor.Contains(id));
}
Related
I hope you are well. Is it possible to query the LazyCache cache using Linq?
// Initialize Class
retVal = (ModelXyz)MemoryCache.Default.Where(u => (u.Value is ModelXyz) &&
(u.Value as ModelXyz).Property1 == abc &&
(u.Value as ModelXyz).Property2 == cde &&
(u.Value as ModelXyz).Property3 == true).Select(x => x.Value).FirstOrDefault();
I'm not sure if I'm barking up the wrong tree but I wanted to create a function to check if an account exists based on all optional parameters so it can be used to pull data depending on whatever you'd like to check on.
Basically the query should be:
where loginName = p1 or loginName = p2 or loginName = p3 but with the paramters all being optional, however at least one will be provided.
This is what I tried so far:
public async Task<bool> CheckAccountExistsAsync(string loginName = "", string authenticatorId = "", string eId = "")
{
if (string.IsNullOrWhiteSpace(loginName) && string.IsNullOrWhiteSpace(authenticatorId) && string.IsNullOrWhiteSpace(eId))
throw new InvalidOperationException("You must pass at least one parameter");
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName) || a.LoginName == loginName)
|| (string.IsNullOrWhiteSpace(authenticatorId) || a.AuthenticatorId == authenticatorId)
|| (string.IsNullOrWhiteSpace(eId) || a.EmployeeId == eId));
}
Problem with this approach is that if I just pass the loginName, then the query is as follows with the condition completely omitted.:
SELECT CASE
WHEN EXISTS (
SELECT 1
FROM [Accounts] AS [a]) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
I'm sure I'm missing something, is there a better approach?
What you are using is applicable for optional and expressions, e.g.
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName) || a.LoginName == loginName)
&& (string.IsNullOrWhiteSpace(authenticatorId) || a.AuthenticatorId == authenticatorId)
&& (string.IsNullOrWhiteSpace(eId) || a.EmployeeId == eId));
For optional or you have to use optional and sub conditions and add additional check for all optional parameters missing, e.g.
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName)
&& string.IsNullOrWhiteSpace(authenticatorId)
&& string.IsNullOrWhiteSpace(eId))
|| (!string.IsNullOrWhiteSpace(loginName) && a.LoginName == loginName)
|| (!string.IsNullOrWhiteSpace(authenticatorId) && a.AuthenticatorId == authenticatorId)
|| (!string.IsNullOrWhiteSpace(eId) && a.EmployeeId == eId));
I have the following code that generates a normal APEX page URL :
PageURL := APEX_UTIL.PREPARE_URL(p_url => 'f?p=' || AppId || ':' || PageAlias || ':' || SessionId ||'::NO::' || Arguments || ':' || ArgumentValues, p_checksum_type => Checksum);
Does anyone know how to generate a URL for a modal page please ?
Thanks.
Cheers,
We are running Elasticsearch Bulk update (elasticsearch uses MVEL)
And we are getting below error
**** COMPILER BUG! REPORT THIS IMMEDIATELY AT http://jira.codehaus.org/browse/mvel2
Expression:
int cIndex= 0;
if(ctx._source.xId == 46461){
if(ctx._source.containsKey("attributes") && ctx._source.attributes.size() > 0){
for(cIndex = 0; cIndex < ctx._source.attributes.size(); cIndex++){
if(ctx._source.attributes[cIndex].attributeName != null && ctx._source.attributes[cIndex].attributeName.indexOf("select") >= 0 && ((ctx._source.attributes[cIndex].attributeValue == "Oy") || (ctx._source.attributes[cIndex].containsKey("attributeValueId") && ctx._source.attributes[cIndex].attributeValueId != null && ctx._source.attributes[cIndex].attributeValueId == "One") && ctx._source.attributes[cIndex].attributeName == "attribute_select_1403272286210_2498")){
ctx._source.attributes[cIndex].attributeValue = "Oye";
ctx._source.attributes[cIndex].attributeValueId = "One";
}
}
}
}
It is working fine for few records and not working for few records.
Did anybody face this issue? Not sure if ES has to update mvel version
Any around is appreciated.
This issue seems to be fixed in "2.2.0", which version of MVEL you are using.
Can you try with <mvel.version>2.2.0.Final</mvel.version>
Also please refer the link here http://jira.codehaus.org/browse/MVEL-299
we have the datasource as :
rgSubjects.DataSource = entity.Student_Subject_MM.Include("Subjects").
Where(p => p.StudentID == _currentStudent.StudentID
&& (p.Subject.SchoolYear == schoolyear || schoolyear == "0")
&& (p.Subject.Semester.Value == sem || sem == 0)
&& (p.Subject.SubjectCode.Contains(searchSubject) || p.Subject.Description.Contains(searchSubject) || p.Subject.Title.Contains(searchSubject))
).Select(p => new {
SubjectCode = p.Subject.SubjectCode.Trim(),
Description = p.Subject.Description.Trim(),
Schedule = p.Subject.Schedule.Trim(),
Room = p.Subject.Room.Trim(),
Instructor = p.Subject.Instructor.LastName + ", " + p.Subject.Instructor.FirstName,
Grade = p.Grade,
Remarks = p.Remarks
});
rgSubjects.DataBind();
How can we change the sizes per column using code-behind in c#.net? thanks a lot.
Does setting the Width property of your columns makes sense? Check out this article about how to operate with auto-generated and declarative columns