1

I have a custom class as follows

  public class LogFiles
{
    private string _fileName;
    private string _path;
    private string _logStatus;

    public LogFiles(string FName, string Path)
    {
        this._path = Path;
        this._fileName = FName;           
    }
    // the below two properties are mapped from DB entities
    public string FName
    {
        get { return this._fileName; }
        set { this._fileName = value; }
    }  
    public string Path
    {
        get { return this._path; }
        set { this._path = value; }
    }          
    // the value for this property will be defined on fly in MainViewModel
    public string LogStatus
    {
        get { return this._logStatus; }
        set { this._logStatus = value; }
    } 
}

I am will set the value for the LogStatus property in my MainViewModel, but to access this property in MainviewModel using linq

something like this,

var get_logStatus = (from a in LogFiles 
                     ordeyby a.LogStatus
                     select a);

This above code is just a guess similar in writing linq to entities, but is it possible for custom classes to access with linq to sql ? please excuse me and correct the question if it sounds stupid.

1 Answer 1

1

You are talking about Linq To Object, because you want querying objects, not entities generated by your DataContext.

Linq To Object have the exact same syntax as Linq To Sql (that's the point of making Linq!). The only thing is Linq To Sql are querying Queryable objects, like an EntitySet of entities, whereas Linq To Object are querying IEnumerable of object.

So first you need an IEnumerable, then you can make your Linq query like this:

var listLogFiles = new List<LogFiles>();
var orderedListLogFiles = (from a in listLogFiles 
                           order by a.LogStatus
                           select a);
Sign up to request clarification or add additional context in comments.

Comments

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.