Entrambi sono un elenco di Provincie.
Ho bisogno di sapere se quelle presenti nel db sono presenti nell'XML.
Così ho fatto:
MyDataContext mdc = new MyDataContext();
var Provincia = from db in mdc.tblProvincies select db.Provincia.Trim().ToUpper();
XDocument xdoc = XDocument.Load(strFilePath);
var xProv = from x in xdoc.Descendants("location")
where x.Element("Prov") != null
select x.Element("Prov").Value.Trim().ToUpper();
var joined = Provincia.Except(xProv);
Il risultato ottenuto è:
Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator
Facendo un paio di ricerche sulle msdn ho risolto in questa maniera:MyDataContext mdc = new MyDataContext();
var Provincia = from db in mdc.tblProvincies select db.Provincia.Trim().ToUpper();
XDocument xdoc = XDocument.Load(strFilePath);
var xProv = from x in xdoc.Descendants("location")
where x.Element("Prov") != null
select x.Element("Prov").Value.Trim().ToUpper();
IEnumerable<string> xObjProv = (from xp in xProv select xp).OfType<string>();
IEnumerable<string> objProv = (from prv in Provincia select prv).OfType<string>();
var joined = objProv.Except(xObjProv);
No comments:
Post a Comment