-2

I've been trying to follow the answer to @Jordan Palmer's question as I'm trying to do the same thing he was trying to do. I'm not seeing how to connect @Jordan Palmer's query (specifically the var variable) with the Records variable that would be in the LoadData() LINQ query shown in the ViewModel code panel. Would it be this:

Records = getTripInformation = from m in connection.tblTrips
            where m.TripDate > DateTime.Today
            select new { m.TripID, m.TripName, m.TripDate, m.ClosingDate, m.PricePerAdult, m.PricePerChild, m.Status };

I need some help on how to connect var to Records.

As @framps asked: "Do you have an example which you can provide for this as I'm struggling with the logic?"

1
  • 1
    what is Rercords in your code you have a typo in the word Records by the way.. also what errors are you getting when running the code.. following the query link example from the other stackoverflow posting.. what seems to be the issue with your not understanding ... Commented Feb 25, 2016 at 18:57

1 Answer 1

0

The Records object is an observable collection. Every time you update it, it updates the datagrid. The LoadData method loads the records from the query into the Records object. For example

var getTripInformation = connection.tblTrips.Where(m => m.TripDate > DateTime.Today);
foreach(var r in getTripInformation)
    Records.Add(r);
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. When I do the equivalent in my query: PersonDBcontext context = new PersonDBcontext(); var query = (from t in context.Persons select new { t.PersonID, t.FirstName, t.LastName, t.Address, t.Age, t.Interests, t.Photo }); foreach (var r in query) Persons.Add(r); I get this error: The best overloaded method match for 'System.Collections.Generic.List<Person>.Add(Person)' has some invalid arguments Appreciate any/all help. Thanks
My bad. I pasted the query without fixing it. Also, your query isn't doing anything except making an anonymous object for every Person. Btw, I don't think your Persons object is an ObservableCollection.
You're right - this was trying as a list. Here's my Person property: private ObservableCollection<Person> _persons = null; public ObservableCollection<Person> Persons { get { return _persons; } set { _persons = value; } } Error:Cannot implicitly convert type List<AnonymousType#1>' to ObservableCollection<Person>. Ideas?
The code where you are initializing the Persons is wrong. It should be similar to Persons = ObservableCollection<Person>(); Then you would add each person from your source using Persons.Add(...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.