|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2010-04-07 22:36:16
Posts: 32,
Visits: 78
|
|
| Can anybody please help me translate the following ocl (from within a ECO object) statement to linq: this.ServiceProvider().GetEcoService<IOclService>().Evaluate(this, "self.CL_Details->select(Attr='SelectThis)") ? I should be simple, but I just can't seem to get it right. How do I get the current object (CL_Master) to be the base for the selection? I have used ocl for a long time, but I want to use linq statements instead, because of type safety and intelli-sense. thnx, Per
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
CL_Details.Where(x => x.Attr == "Some text").Select(x);
====
Pete
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2010-04-07 22:36:16
Posts: 32,
Visits: 78
|
|
| Wouldn't that solution load all CL_Detail, instead of just the ones that are linked to the current CL_Master ? In ocl, that is not good practice, because all the details are first loaded, and then queried. But I'm not that familiar with linq yet.
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
Per (2009-10-13) Wouldn't that solution load all CL_Detail, instead of just the ones that arelinked to the current CL_Master ?
In ocl, that is not good practice, because all the details are first loaded,and thenqueried. But I'm not that familiar with linq yet.
If you want InDB evaluation then try evaluating like this
EcoSpace.PsQuery().Where(x => x.Name == "Meh" && x.Parent = this).Select(x);
====
Pete
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2010-04-07 22:36:16
Posts: 32,
Visits: 78
|
|
Sorry for not being clear about what I'm trying to achieve  I trying to save a roundtrip to the database if possible, and create an MemQuery, but with CL_Master as the point of origin. The ocl statement from the original post: "self.CL_Detail->( <select something unimportant> )" The culprit is the "self.CL_Detail", in a MemQuery. Is that possible ? If yes, then how ? Per
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
You have two choices
1: In memory - The first time you do it ECO will load all children for this parent into memory and THEN apply the criteria
Select * from children where ParentID = xxxxxxx;
It doesn't matter if you have 10,000,000 Children as long as you only have a relatively small amount per Parent - it won't load ALL Children, just the relevant children.
2: In PS - This is evaluated in the DB every time. You might want to do this if you have 10,000,000 children PER PARENT.
Does that help?
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Today @ 20:20:07
Posts: 241,
Visits: 7 537
|
|
Per (2009-10-12)
Can anybody please help me translate the following ocl (from within a ECO object) statement to linq: this.ServiceProvider().GetEcoService<IOclService>().Evaluate(this, "self.CL_Details->select(Attr='SelectThis)") ? thnx, Per I think he wants (in C# anyways): var results = from detail in EcoSpace(CurrentMaster.CL_Details) where detail.Attr == "SelectThis" select detail; But... I tried several versions in my project and "results" was always empty no matter what records were in the CurrentMaster.CL_Details list - even if I left off the where clause alltogether. This is my exact line I tried in my project, where game is an instance of a ECO class that has an IEcoList<Team> called Teams: var results = from team in EcoSpace.PSQuery(game.Teams) where team.Name == "Black" select team;Something might be broke in general though because I also tried: var results = from team in EcoSpace.PSQuery<Team>() select team; And got empty results even though my game.Teams list had teams in it. That should have gotten me all the teams in my system I thought!? We really need a "how to" for Linq - or at least I do.
Rick Weyrauch
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2010-04-07 22:36:16
Posts: 32,
Visits: 78
|
|
Yep, Rick - that is exactly what I want And yes, I could also use a "HowTo" linq.Peter - it's not because I can't get the record(s) from an ocl, but I can't figure out the linq syntax. I'm aware how ocl fetches the records from the database, but that is not the issue. It's pure linq syntax. How do I "root" a linq statement, from an existing instance ? Hints - anyone ?
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290,
Visits: 2 617
|
|
try writing it as pseudo SQL, maybe then I will understand what you want
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Today @ 20:20:07
Posts: 241,
Visits: 7 537
|
|
| ok, well I figured out why mine was not working. PSQuery<>() does not work when you are using an XML file for storage. I switched to MS-SQL DB and now it is all "working". I quote it because it is a very qualified working. With exactly one match for the first Linq, this works: var class1 = from c in EcoSpace.PSQuery<Class1>() where c.Attribute1 == "ccc" select c;foreach (var q in class1) { DataContext = from c in EcoSpace.PSQuery(q.Class2) where c.Foo == "Oops2" select c; }This did not, but should (null check is missing, I know): var class1 = (from c in EcoSpace.PSQuery<Class1>() where c.Attribute1 == "ccc" select c).FirstOrDefault();DataContext = from c in EcoSpace.PSQuery(class1.Class2) where c.Foo == "Oops2" select c;Then, on top of FirstOrDefault() not working, the SQL the two Linq's generated were different but I would think they should be very similar. I am investigating this more though because it was 2:00 AM when I was trying it.
Rick Weyrauch
|
|
|
|