here is my sample xml file:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<title>Title goes here</title>
<author><name>None</name></author>
<source>
<title>Adhocs Source - Adhocs Section</title>
<id>None</id>
<updated>2015-07-21T17:45:20.387248Z</updated>
</source>
<link rel="alternate" href="http://www.example.com/" />
<id>http://www.example.com/</id>
<updated>2015-07-21T17:45:20.387248Z</updated>
<published>2015-07-21T17:45:20.387248Z</published>
<summary>sample desc goes here...</summary>
<media:thumbnail
xmlns:media="http://search.yahoo.com/mrss/"
url="http://mscrmblog.net/wp-content/uploads/2013/10/iframe-loading.png" />
</entry>
</feed>
when i am trying to read this using c# Linq to XML query using below code:
XElement _atom = XElement.Load(atom);
XNamespace nsMedia = "http://search.yahoo.com/mrss/";
XNamespace nsAtom = "http://www.w3.org/2005/Atom";
var temp = (from item in _atom.Descendants(nsAtom + "entry")
select new FinalListToBeDisplayed()
{
Title = item.Element(nsAtom + "title") == null ? "" : item.Element(nsAtom + "title").Value,
Description = item.Element(nsAtom + "summary") == null ? "" : item.Element(nsAtom + "summary").Value,
PublishedDate = item.Element(nsAtom + "published") == null ? "" : item.Element(nsAtom + "published").Value,
Link = item.Element(nsAtom + "link") == null ? "" : item.Element(nsAtom + "link").Attribute("href") == null ? "" : item.Element(nsAtom + "link").Attribute("href").Value,
Image = item.Element(nsMedia + "thumbnail") == null ? "" : item.Element(nsMedia + "thumbnail").Attribute(nsAtom + "url") != null ? item.Element(nsMedia + "thumbnail").Attribute(nsAtom + "url").Value : ""
}).ToList();
Image is not capturing at any moment, i.e. the above code is not able to read thumbnails . Please help me to understand the issue in the above code.
Try this
XElement _atom = XElement.Load(atom);
XNamespace nsMedia = "http://search.yahoo.com/mrss/";
XNamespace nsAtom = "http://www.w3.org/2005/Atom";
var temp = (from item in _atom.Descendants(nsAtom + "entry")
select new
{
Title = item.Element(nsAtom + "title") == null ? "" : item.Element(nsAtom + "title").Value,
Description = item.Element(nsAtom + "summary") == null ? "" : item.Element(nsAtom + "summary").Value,
PublishedDate = item.Element(nsAtom + "published") == null ? "" : item.Element(nsAtom + "published").Value,
Link = item.Element(nsAtom + "link") == null ? "" : item.Element(nsAtom + "link").Attribute("href") == null ? "" : item.Element(nsAtom + "link").Attribute("href").Value,
Image = item.Element(nsMedia + "thumbnail") == null ? "" : item.Element(nsMedia + "thumbnail").Attribute("url") != null ? item.Element(nsMedia + "thumbnail").Attribute("url").Value : ""
}).ToList();
The issue is the attribute name for url. url does not have a namespace, but you are including the http://www.w3.org/2005/Atom namespace as part of the name. Remove this and use url and it will work.
I'd also comment that you can use the methods that return a sequence combined with the explicit conversions built into XElement and XAttribute to avoid your null checks. This achieves the same result but is a lot cleaner:
Title = (string)item.Element(nsAtom + "title") ?? "",
Description = (string)item.Element(nsAtom + "summary") ?? "",
PublishedDate = (string)item.Element(nsAtom + "published") ?? "",
Link = (string)item.Elements(nsAtom + "link")
.Attributes("href")
.SingleOrDefault() ?? "",
Image = (string)item.Elements(nsMedia + "thumbnail")
.Attributes("url")
.SingleOrDefault() ?? ""
Related
The following works just fine:
myStatements = db.Statements.Select(s => new StatementModel
{
StatmentId = s.StatementId,
EmployeeNumber = s.EmployeeNumber,
FirstName = s.Employee.FirstName,
LastName = s.Employee.LastName,
PlanVariantType = s.Employee.PlanVariantType != null ? s.Employee.PlanVariantType.PlanVariantTypeName : "",
FiscalPeriod = s.FiscalPeriod != null ? s.FiscalPeriod.FiscalPeriodName : "",
CostCenterId = s.Employee.CostCenterId,
EVPName = s.Employee.CostCenter.Evp != null ? s.Employee.CostCenter.Evp.FirstName + " " + s.Employee.CostCenter.Evp.LastName : "",
SVPName = s.Employee.CostCenter.Svp != null ? s.Employee.CostCenter.Svp.FirstName + " " + s.Employee.CostCenter.Svp.LastName : "",
LOBMgrName = s.Employee.CostCenter.Lobmgr != null ? s.Employee.CostCenter.Lobmgr.FirstName + " " + s.Employee.CostCenter.Lobmgr.LastName : "",
AdminApprovalStatus = s.AdminApprovalStatus.ApprovalStatusName,
StatementStatus = s.StatementStatus.StatementStatusName,
AmountDue = s.AmountDue
}).ToList();
But if I add a simple WHERE clause it throws an exception saying it can't be translated:
myStatements = db.Statements.Select(s => new StatementModel
{
StatmentId = s.StatementId,
EmployeeNumber = s.EmployeeNumber,
FirstName = s.Employee.FirstName,
LastName = s.Employee.LastName,
PlanVariantType = s.Employee.PlanVariantType != null ? s.Employee.PlanVariantType.PlanVariantTypeName : "",
FiscalPeriod = s.FiscalPeriod != null ? s.FiscalPeriod.FiscalPeriodName : "",
CostCenterId = s.Employee.CostCenterId,
EVPName = s.Employee.CostCenter.Evp != null ? s.Employee.CostCenter.Evp.FirstName + " " + s.Employee.CostCenter.Evp.LastName : "",
SVPName = s.Employee.CostCenter.Svp != null ? s.Employee.CostCenter.Svp.FirstName + " " + s.Employee.CostCenter.Svp.LastName : "",
LOBMgrName = s.Employee.CostCenter.Lobmgr != null ? s.Employee.CostCenter.Lobmgr.FirstName + " " + s.Employee.CostCenter.Lobmgr.LastName : "",
AdminApprovalStatus = s.AdminApprovalStatus.ApprovalStatusName,
StatementStatus = s.StatementStatus.StatementStatusName,
AmountDue = s.AmountDue
}).Where(s => s.StatementStatusId == "PAA").ToList();
The exception message is a mess and isn't helpful beyond telling me that it couldn't be translated.
So what's the issue with the WHERE clause?
Try this. Use where clause first then projection.
myStatements = db.Statements.Where(s => s.StatementStatusId == "PAA").Select(s => new StatementModel
{
StatmentId = s.StatementId,
EmployeeNumber = s.EmployeeNumber,
FirstName = s.Employee.FirstName,
LastName = s.Employee.LastName,
PlanVariantType = s.Employee.PlanVariantType != null ? s.Employee.PlanVariantType.PlanVariantTypeName : "",
FiscalPeriod = s.FiscalPeriod != null ? s.FiscalPeriod.FiscalPeriodName : "",
CostCenterId = s.Employee.CostCenterId,
EVPName = s.Employee.CostCenter.Evp != null ? s.Employee.CostCenter.Evp.FirstName + " " + s.Employee.CostCenter.Evp.LastName : "",
SVPName = s.Employee.CostCenter.Svp != null ? s.Employee.CostCenter.Svp.FirstName + " " + s.Employee.CostCenter.Svp.LastName : "",
LOBMgrName = s.Employee.CostCenter.Lobmgr != null ? s.Employee.CostCenter.Lobmgr.FirstName + " " + s.Employee.CostCenter.Lobmgr.LastName : "",
AdminApprovalStatus = s.AdminApprovalStatus.ApprovalStatusName,
StatementStatus = s.StatementStatus.StatementStatusName,
AmountDue = s.AmountDue
}).ToList();
Problem here that you have custom projection. It means that LINQ translator knows only fields which are explicitly mapped. StatementStatusId has no mapping and Translator throws error. Add mapping and query will work:
myStatements = db.Statements.Select(s => new StatementModel
{
StatmentId = s.StatementId,
EmployeeNumber = s.EmployeeNumber,
FirstName = s.Employee.FirstName,
LastName = s.Employee.LastName,
PlanVariantType = s.Employee.PlanVariantType != null ? s.Employee.PlanVariantType.PlanVariantTypeName : "",
FiscalPeriod = s.FiscalPeriod != null ? s.FiscalPeriod.FiscalPeriodName : "",
CostCenterId = s.Employee.CostCenterId,
EVPName = s.Employee.CostCenter.Evp != null ? s.Employee.CostCenter.Evp.FirstName + " " + s.Employee.CostCenter.Evp.LastName : "",
SVPName = s.Employee.CostCenter.Svp != null ? s.Employee.CostCenter.Svp.FirstName + " " + s.Employee.CostCenter.Svp.LastName : "",
LOBMgrName = s.Employee.CostCenter.Lobmgr != null ? s.Employee.CostCenter.Lobmgr.FirstName + " " + s.Employee.CostCenter.Lobmgr.LastName : "",
AdminApprovalStatus = s.AdminApprovalStatus.ApprovalStatusName,
StatementStatus = s.StatementStatus.StatementStatusName,
AmountDue = s.AmountDue,
// missing mapping
StatementStatusId = s.StatementStatusId
}).Where(s => s.StatementStatusId == "PAA").ToList();
I am using VS2013 and crystal report 2013
I am passing 30 parameters to crystal report.
It is working fine for 5 times, Then I got the next error:-
Memory Full. Not Enough memory for operation.
What I tried so far:-
using CrystalReport1.Refresh(); without solving the problem.
Appreciate any help.
Edit 1:-
I know maybe my question has lack of info but I think there is no any details could help you, any ways here you are the extra info I hope it will be useful.
I have Application as next:-
when I click Print it is working fine as next
if I close the window and press Print again it is working fine for 5 or 6 times,
then I faced the next error:-
Edit 2:-
My code is:-
1) Create new form and drag and drop crystal report viewer.
2) at the load event I wrote the next code:-
private void frmReport_Load(object sender, EventArgs e)
{
try
{
CrystalReport11.SetParameterValue("pName", PatientName);
CrystalReport11.SetParameterValue("pAge", Age);
CrystalReport11.SetParameterValue("pDate", Date);
CrystalReport11.SetParameterValue("P1", Number1);
CrystalReport11.SetParameterValue("P2", Number2);
CrystalReport11.SetParameterValue("P3", Number3);
CrystalReport11.SetParameterValue("P4", Number4);
CrystalReport11.SetParameterValue("P5", Number5);
CrystalReport11.SetParameterValue("P6", Number6);
CrystalReport11.SetParameterValue("P7", Number7);
CrystalReport11.SetParameterValue("pDrugsName1", DrugName1);
CrystalReport11.SetParameterValue("pDrugsName2", DrugName2);
CrystalReport11.SetParameterValue("pDrugsName3", DrugName3);
CrystalReport11.SetParameterValue("pDrugsName4", DrugName4);
CrystalReport11.SetParameterValue("pDrugsName5", DrugName5);
CrystalReport11.SetParameterValue("pDrugsName6", DrugName6);
CrystalReport11.SetParameterValue("pDrugsName7", DrugName7);
CrystalReport11.SetParameterValue("pQTY1", QTY1);
CrystalReport11.SetParameterValue("pQTY2", QTY2);
CrystalReport11.SetParameterValue("pQTY3", QTY3);
CrystalReport11.SetParameterValue("pQTY4", QTY4);
CrystalReport11.SetParameterValue("pQTY5", QTY5);
CrystalReport11.SetParameterValue("pQTY6", QTY6);
CrystalReport11.SetParameterValue("pQTY7", QTY7);
CrystalReport11.SetParameterValue("pTimeOfUse1", TimeOfUse1);
CrystalReport11.SetParameterValue("pTimeOfUse2", TimeOfUse2);
CrystalReport11.SetParameterValue("pTimeOfUse3", TimeOfUse3);
CrystalReport11.SetParameterValue("pTimeOfUse4", TimeOfUse4);
CrystalReport11.SetParameterValue("pTimeOfUse5", TimeOfUse5);
CrystalReport11.SetParameterValue("pTimeOfUse6", TimeOfUse6);
CrystalReport11.SetParameterValue("pTimeOfUse7", TimeOfUse7);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and I am calling the form via next code:-
DrugName1 = (txtDrugsName1.Text == string.Empty) ? " " : txtDrugsName1.Text;
DrugName2 = (txtDrugsName2.Text == string.Empty) ? " " : txtDrugsName2.Text;
DrugName3 = (txtDrugsName3.Text == string.Empty) ? " " : txtDrugsName3.Text;
DrugName4 = (txtDrugsName4.Text == string.Empty) ? " " : txtDrugsName4.Text;
DrugName5 = (txtDrugsName5.Text == string.Empty) ? " " : txtDrugsName5.Text;
DrugName6 = (txtDrugsName6.Text == string.Empty) ? " " : txtDrugsName6.Text;
DrugName7 = (txtDrugsName7.Text == string.Empty) ? " " : txtDrugsName7.Text;
Number1 = (txtDrugsName1.Text == string.Empty) ? " " : "1";
Number2 = (txtDrugsName2.Text == string.Empty) ? " " : "2";
Number3 = (txtDrugsName3.Text == string.Empty) ? " " : "3";
Number4 = (txtDrugsName4.Text == string.Empty) ? " " : "4";
Number5 = (txtDrugsName5.Text == string.Empty) ? " " : "5";
Number6 = (txtDrugsName6.Text == string.Empty) ? " " : "6";
Number7 = (txtDrugsName7.Text == string.Empty) ? " " : "7";
QTY1 = (cmbQTY1.Text == string.Empty) ? " " : cmbQTY1.Text;
QTY2 = (cmbQTY2.Text == string.Empty) ? " " : cmbQTY2.Text;
QTY3 = (cmbQTY3.Text == string.Empty) ? " " : cmbQTY3.Text;
QTY4 = (cmbQTY4.Text == string.Empty) ? " " : cmbQTY4.Text;
QTY5 = (cmbQTY5.Text == string.Empty) ? " " : cmbQTY5.Text;
QTY6 = (cmbQTY6.Text == string.Empty) ? " " : cmbQTY6.Text;
QTY7 = (cmbQTY7.Text == string.Empty) ? " " : cmbQTY7.Text;
TimeOfUse1 = (cmbTimeOfUse1.Text == string.Empty) ? " " : cmbTimeOfUse1.Text;
TimeOfUse2 = (cmbTimeOfUse2.Text == string.Empty) ? " " : cmbTimeOfUse2.Text;
TimeOfUse3 = (cmbTimeOfUse3.Text == string.Empty) ? " " : cmbTimeOfUse3.Text;
TimeOfUse4 = (cmbTimeOfUse4.Text == string.Empty) ? " " : cmbTimeOfUse4.Text;
TimeOfUse5 = (cmbTimeOfUse5.Text == string.Empty) ? " " : cmbTimeOfUse5.Text;
TimeOfUse6 = (cmbTimeOfUse6.Text == string.Empty) ? " " : cmbTimeOfUse6.Text;
TimeOfUse7 = (cmbTimeOfUse7.Text == string.Empty) ? " " : cmbTimeOfUse7.Text;
frmReport obj = new frmReport(
txtPatientName.Text,
nudAge.Value.ToString(),
dtpDate.Text,
DrugName1,
DrugName2,
DrugName3,
DrugName4,
DrugName5,
DrugName6,
DrugName7,
QTY1,
QTY2,
QTY3,
QTY4,
QTY5,
QTY6,
QTY7,
TimeOfUse1,
TimeOfUse2,
TimeOfUse3,
TimeOfUse4,
TimeOfUse5,
TimeOfUse6,
TimeOfUse7,
Number1,
Number2,
Number3,
Number4,
Number5,
Number6,
Number7
);
obj.ShowDialog();
I had the same problem and this worked for me too:
into frmReport_FormClosing Type crystalReportViewer1.Dispose(); and CrystalReport11.Dispose();
i'm making a web-service where i'm calling data-objects who are created directly through linq, i was wondering, how i can convert DateTime? directly to string?, this, because i can't convert the DateTime? to DateTime and then to string through a variable or a what not, because linq don't let me.
Here's the code:
lista = (from p in db.Acciones
select new ItemAcciones
{
ID_Accion = p.ID_Accion,
FechaHora = p.FechaHora != null ? (DateTime)p.FechaHora : DateTime.Now,
//ShowFechaHora = !String.IsNullOrWhiteSpace(((DateTime)p.FechaHora).ToString("HH:mm")) ? ((DateTime)p.FechaHora).ToString("HH:mm") : DateTime.Now.ToString("HH:mm"),
ID_EmpresaNombre = p.Empresas.EmpresaNombre,
ID_ResponsableNombre = p.Responsables.LoginID,
ID_ContactoNombre = p.Contactos.Nombres + " " + p.Contactos.Paterno + " " + p.Contactos.Materno,
ID_AccionTipoNombre = p.AccionTipos.AccionTipoGlosa,
ID_AccionEstadoNombre = p.AccionEstados.AccEstGlosa,
AccionGlosa = p.AccionGlosa,
ID_Empresa = p.ID_Empresa,
AccionDescripcion = p.AccionDescripcion,
ID_Negocio = (int?)p.ID_Negocio ?? 0,
ID_Contacto = p.ID_Contacto,
ID_AccionTipo = p.ID_AccionTipo,
ID_AccionEstado = p.ID_AccionEstado,
ID_ProgFecha = p.ID_ProgFecha != null ? (int)p.ID_ProgFecha : 0,
ShowID_ProgFecha = String.IsNullOrWhiteSpace(p.ID_ProgFecha.ToString()) ?? p.ID_ProgFecha.ToString() : "--/--/----",
//ShowID_ProgFecha = StringAEstilizarComoDate(Convert.ToString(p.ID_ProgFecha)),
ID_ProgHora = p.ID_ProgHora != null ? (int)p.ID_ProgHora : 0,
//ShowID_ProgHora = StringAEstilizarComoHora(Convert.ToString(p.ID_ProgHora)),
ID_EjecFecha = p.ID_EjecFecha != null ? (int)p.ID_EjecFecha : 0,
//ShowID_EjecFecha = StringAEstilizarComoDate(Convert.ToString(p.ID_EjecFecha)),
ID_EjecHora = p.ID_EjecHora != null ? (int)p.ID_EjecHora : 0,
//ShowID_EjecHora = StringAEstilizarComoHora(Convert.ToString(p.ID_EjecHora)),
ID_Responsable = p.ID_Responsable,
EmpresaRUTCompleto = p.Empresas.EmpresaRut.ToString() + "-" + p.Empresas.EmpresaDV,
ID_NegocioNombre = p.Negocios.ProyectoNombre,
}).ToList();
Any question, suggestion or comment to improve the question would be appreciated as well as the answer.
It's a manually solution, but you can use SqlFunctions to handle the string for your Date.
var qqqq = db.YourTable.Select(q => (q.YourDate == null ? "" : (SqlFunctions.DateName("day",q.YourDate) + "/" + SqlFunctions.DateName("month", q.YourDate) + "/" + SqlFunctions.DateName("year", q.YourDate) + " " + SqlFunctions.DateName("hour", q.YourDate) + " " + SqlFunctions.DateName("minute", q.YourDate)))).ToList();
Hope that helps. =)
So I have a relatively simple query, but it is not matching the full_name text field even though I can see the data is there and is an exact match?
I made sure to checkk the fullName parameter being passed in is the correct value. I couldn't find any documentation verifying if I needed the single quotes or not, but without it an error was thrown.
Anyone have any suggestions?
Code in question with the SQL statement?
public static ObservableCollection<ShiftView> GetShifts(DateTime? start, DateTime? stop, string fullName, bool? closed)
{
ObservableCollection<ShiftView> shifts = new ObservableCollection<ShiftView>();
// INFO: Not intended to retrieve a lot of records as there is no caching....
OleDbCommand cmd = new OleDbCommand("SELECT profiles.profile_id, profiles.full_name, shifts.start, shifts.stop, shifts.start_log, shifts.stop_log, shifts.start_notes, shifts.stop_notes FROM shifts, profiles WHERE " +
(start.HasValue ? "(shifts.start>=#start) AND " : "") +
(stop.HasValue ? "(shifts.stop<=#stop) AND " : "") +
(fullName != null ? "profile.full_name='#full_name' AND " : "") +
(closed.HasValue ? "shifts.closed=#closed AND " : "") +
"(shifts.profile_id=profiles.profile_id)"
);
if (start.HasValue)
cmd.Parameters.AddWithValue("#start", start.Value.ToString());
if (stop.HasValue)
cmd.Parameters.AddWithValue("#stop", stop.Value.ToString());
if (fullName != null)
cmd.Parameters.AddWithValue("#full_name", fullName);
if (closed.HasValue)
cmd.Parameters.AddWithValue("#closed", closed);
OleDbDataReader reader = Database.Read(cmd);
DateTime? _stop, _stopLog;
while(reader.Read())
{
Console.WriteLine("!");
// shorthand form if's with ? does not work here.
if (reader.IsDBNull(reader.GetOrdinal("stop")))
_stop = null;
else
_stop = reader.GetDateTime(reader.GetOrdinal("stop"));
if (reader.IsDBNull(reader.GetOrdinal("stop_log")))
_stopLog = null;
else
_stopLog = reader.GetDateTime(reader.GetOrdinal("stop_log"));
shifts.Add(new ShiftView(
reader.GetString(reader.GetOrdinal("profile_id")),
reader.GetString(reader.GetOrdinal("full_name")),
reader.GetDateTime(reader.GetOrdinal("start")),
_stop,
reader.GetDateTime(reader.GetOrdinal("start_log")),
_stopLog,
reader.GetString(reader.GetOrdinal("start_notes")),
reader.GetString(reader.GetOrdinal("stop_notes"))
));
}
return shifts;
}
The above code gets called from this button press:
private void ShowStatsButton_Click(object sender, RoutedEventArgs e)
{
DateTime? start = StartDatePicker.SelectedDate;
DateTime? stop = StopDatePicker.SelectedDate;
string name = NameComboBox.Text;
if (name.Equals("Everyone"))
name = null;
if (stop.HasValue)
stop = stop.Value.AddDays(1);
StatsGridView.ItemsSource = Shift.GetShifts(start, stop, name, true);
}
This filters the date range and if there is a full name. I ensure there is a valid value for name.
I think that the problem is in here, you need to remove '' from full_name line:
OleDbCommand cmd = new OleDbCommand("SELECT profiles.profile_id, profiles.full_name, shifts.start, shifts.stop, shifts.start_log, shifts.stop_log, shifts.start_notes, shifts.stop_notes FROM shifts, profiles WHERE " +
(start.HasValue ? "(shifts.start>=#start) AND " : "") +
(stop.HasValue ? "(shifts.stop<=#stop) AND " : "") +
(fullName != null ? "profile.full_name='#full_name' AND " : "") + <-- remove '' from '#full_name'
(closed.HasValue ? "shifts.closed=#closed AND " : "") +
"(shifts.profile_id=profiles.profile_id)"
);
and do this:
OleDbCommand cmd = new OleDbCommand("SELECT profiles.profile_id, profiles.full_name, shifts.start, shifts.stop, shifts.start_log, shifts.stop_log, shifts.start_notes, shifts.stop_notes FROM shifts, profiles WHERE " +
(start.HasValue ? "(shifts.start>=#start) AND " : "") +
(stop.HasValue ? "(shifts.stop<=#stop) AND " : "") +
(fullName != null ? "profile.full_name=#full_name AND " : "") +
(closed.HasValue ? "shifts.closed=#closed AND " : "") +
"(shifts.profile_id=profiles.profile_id)"
);
I hope this help
It turns out that adding in the table name was the cause of the problem. Why this is the case, is uncertain and I will follow up with another question specific to that.
So the solution I eventually went with to change the following:
OleDbCommand cmd = new OleDbCommand("SELECT profiles.profile_id, profiles.full_name, shifts.start, shifts.stop, shifts.start_log, shifts.stop_log, shifts.start_notes, shifts.stop_notes FROM shifts, profiles WHERE " +
(start.HasValue ? "(shifts.start>=#start) AND " : "") +
(stop.HasValue ? "(shifts.stop<=#stop) AND " : "") +
(fullName != null ? "profile.full_name='#full_name' AND " : "") + // this is where the problem is
(closed.HasValue ? "shifts.closed=#closed AND " : "") +
"(shifts.profile_id=profiles.profile_id)"
);
and change it to:
(fullName != null ? "full_name=#full_name AND " : "") + // Notice I removed the table name and just straight referenced the field.
EDIT:
I updated the above correct line to remove single quotes, that I accidentally left in copy and pasting (numero uno coding mistake!).
I also discovered why I kept getting an error staring at it for hours. Turns out, the table is called "profiles", not "profile" and therefore when I removed the table name it worked!
So an alternative solution is:
(fullName != null ? "profiles.full_name=#full_name AND " : "")
Silly, I know. Feel stupid now.
I have the following:
var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let text = properties.Element(d + "Text")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
select new Content
{
Text = text.Value,
Title = title.Value
};
What I would like to do is to add a where so that only some items are placed into result. How can I add in the condition:
partitionKey.Substring(2, 2) == "03" && text != null
to the select?
Just add the condition before the select:
var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let text = properties.Element(d + "Text")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
where partitionKey.Value.Substring(2, 2) == "03"
where text != null
select new Content
{
Text = text.Value,
Title = title.Value
};
instead of
where partitionKey.Substring(2, 2) == "03" && text != null
use
where partitionKey.Value.Substring(2, 2) == "03" && text != null
partitionKey is of type XElement, when you need it's value.
Specify where before the select:
var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let text = properties.Element(d + "Text")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
where partitionKey.Substring(2, 2) == "03" && text != null
select new Content
{
Text = text.Value,
Title = title.Value
};
var result =
from entry in feed.Descendants(a + "entry")
let content = entry.Element(a + "content")
let properties = content.Element(m + "properties")
let text = properties.Element(d + "Text")
let title = properties.Element(d + "Title")
let partitionKey = properties.Element(d + "PartitionKey")
where partitionKey.Value.Substring(2, 2) == "03" && text != null
select new Content
{
Text = text.Value,
Title = title.Value
};
I suggest to use a linquer software which converts SQL scripts into LINQ ,imagine this at a time of Inner Joins and more complecx query ?
visit : www.sqltolinq.com/
It is very handy tool!!