FeatureLayer featLyr = mp.MainMap.Layers["Layer1"] as FeatureLayer; var flSource = featLyr.GraphicsSource; var newSource = from fl in flSource join db in this.elementListItems on (int)fl.Attributes["OBJECTID"] equals (int)db.FID select new { db.FID, ... }; featLyr.GraphicsSource = (IEnumerable<Graphic>)newSource;Solved! Go to Solution.
foreach(var pair in featLyr.Graphics.Join(this.elementListItems, fl => (int) fl.Attributes["OBJECTID"], db => (int) db.FID, (fl,db) => new {fl, db})) { pair.fl.Attributes["Aloitusajankohta"] = pair.db.Aloitusajankohta; pair.fl.Attributes["Nimi"] = pair.db.Nimi; }var newSource = from fl in flSource
join db in this.elementListItems on (int)fl.Attributes["OBJECTID"] equals (int)db.FID
select new Graphic()
{
Geometry=fl.Geometry,
Attributes=fl.Attributes.Concat(new Dictionary<string,object>()
{
{"StartDate", db.StartDate},
{"ValueA", db.ValueA}
}
)
};var graphics = from g in l.Graphics where ids.Contains((int)g.Attributes["OBJECTID"]) select g;
only to have Visual Studio tell me that Attributes is read-only. Why? It shouldn't be, should it? I guess I'm pretty much stuck
var newSource = flSource.Join(this.elementListItems, fl => (int) fl.Attributes["OBJECTID"], db => (int) db.Key,
(fl, db) =>
{
var g = new Graphic {Geometry = fl.Geometry};
g.Attributes["StartDate"] = db.StartDate;
g.Attributes["ValueA"] = db.ValueA;
return g;
});var flSource = featLyr.GraphicsSource;
var newSource = flSource.Join(this.elementListItems, fl => (int) fl.Attributes["OBJECTID"], db => (int) db.FID,
(fl, db) =>
{
var g = new Graphic {Geometry = fl.Geometry};
g.Attributes["Aloitusajankohta"] = db.Aloitusajankohta;
g.Attributes["Nimi"] = db.Nimi;
return g;
});
featLyr.GraphicsSource = (IEnumerable<Graphic>)newSource;var flSource = featLyr.Graphics;
featLyr.GraphicsSource = (IEnumerable<Graphic>)newSource;
foreach(var pair in featLyr.Graphics.Join(this.elementListItems, fl => (int) fl.Attributes["OBJECTID"], db => (int) db.FID, (fl,db) => new {fl, db})) { pair.fl.Attributes["Aloitusajankohta"] = pair.db.Aloitusajankohta; pair.fl.Attributes["Nimi"] = pair.db.Nimi; }You can't mix the usage of GraphicsSource and of Graphics in the same GraphicsLayer. It's either GraphicsSource or Graphics but not both.
That explain's your issues 1 and 2.
Issue 3 is because you can't cast an IEnumerable to an IList (a list is enumerable but an enumerable is not always a list).
I would seem that by default Graphics is used for feature layers as it contains a collection of graphics automatically when I retrieve it.
I'm beginning to wonder whether I could achieve this functionality simply by looping through the features and setting the values for each one individually...
foreach(var pair in featLyr.Graphics.Join(this.elementListItems, fl => (int) fl.Attributes["OBJECTID"], db => (int) db.FID, (fl,db) => new {fl, db}))
{
pair.fl.Attributes["Aloitusajankohta"] = pair.db.Aloitusajankohta;
pair.fl.Attributes["Nimi"] = pair.db.Nimi;
}