Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Filtering a Table in LINQ based on Roles

Avatar of WeirdoBc
WeirdoBc asked on
.NET Programming
1 Comment1 Solution441 ViewsLast Modified:
Hello,
I have a table which has a colomn named EditorGroup. I want to filter what the user sees on this table depending if he is in the EditorGroup or not. The Roles.IsUserInRole(EditorGroup) works fine, but not in LINQ. It tells me that the method cannot be translated to SQL. I looked around the web about that error and it says I should type it as an expression, but how can we type a system function as an expression?

I also tried using the IsUserRole function inside a property, but I still get the same message.

What are my options?

Thanks,

WeirdoBc
Partial Public Class RegInfoBDDataContext

    Public ReadOnly Property EtabsByRoles() As System.Collections.Generic.IEnumerable(Of Etab)
        Get
            If Not Roles.IsUserInRole("TCRAL Editeurs TCR") Then
                Return Me.Etabs.Where(Function(e) e.IsUserInRole).AsEnumerable
            Else
                Return Me.Etabs.AsEnumerable
            End If
        End Get
    End Property
End Class

Partial Public Class Etab
    Public ReadOnly Property IsUserInRole() As Boolean
        Get
            Return Roles.IsUserInRole(Me.EditorGroup)
        End Get
    End Property
End Class
ASKER CERTIFIED SOLUTION
Avatar of WeirdoBc
WeirdoBc

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers