C#C
C#4y ago
Alex Frost

Help with Implicit Explicit operators

This is my operator definition
public static implicit operator EventViewModel(Entry e)
        {
            EventViewModel viewModel = new EventViewModel();
            viewModel.Id = e.Id;
            viewModel.Title = e.Title;
            viewModel.StartDate = e.DateStart;
            viewModel.EndDate = e.DateEnd;
            return viewModel;
        }

I've not been able to find the exacts. With this definition, will it convert from Entry to ViewModel or ViewModel to Entry? Because, with the said implementation, following conversion doesn't work:
EventData = Context.Entries.Where(e => e.UserId == UserId);
The error is Can't convert from IQueryable<Entry> to IQueryable<ViewModel>
Was this page helpful?