Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 600671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:37:51+00:00 2026-05-13T16:37:51+00:00

I have a class that needs a property set inside a LINQ-to-SQL query. My

  • 0

I have a class that needs a property set inside a LINQ-to-SQL query. My first attempt was to have a “setter” method that would return the object instance and could be used in my select, like this:

public partial class Foo
{
    public DateTime RetrievalTime { get; set; }

    public Foo SetRetrievalTimeAndReturnSelf ( DateTime value )
    {
        RetrievalTime = value;
        return this;
    }
}

....

from foo in DataContext.GetTable<Foo> select foo.SetRetrievalTimeAndReturnSelf();

Unfortunately, such a query throws an exception like this: “System.NotSupportedException: Method ‘Foo.SetRetrievalTime(System.DateTime)’ has no supported translation to SQL”.

Is there any alternative to converting the result to a list and iterating over it? The query is used in a custom “Get” method that wraps the DataContext.GetTable method, so will be used as the base for many other queries. Immediately converting a potentially-large result set to a list would not be optimal.

UPDATE

Here’s a better example of what I’m trying to do, updated with Jason’s proposed solution:

protected IQueryable<T> Get<T>() where T : class, ISecurable
{
    // retrieve all T records and associated security records
    var query = from entity in DataContext.GetTable<T> ()
                from userEntityAccess in DataContext.GetTable<UserEntityAccess> ()
                where userEntityAccess.SysUserId == CurrentUser.Id
                    && entity.Id == userEntityAccess.EntityId
                    && userEntityAccess.EntityClassName == typeof ( T ).Name
                select new { entity, userEntityAccess };

    return query.AsEnumerable ()
        .Select ( item =>
        {
            item.entity.CanRead = item.userEntityAccess.CanRead;
            item.entity.CanWrite = item.userEntityAccess.CanWrite;
            item.entity.CanDelete = item.userEntityAccess.CanDelete;
            return item.entity;
        } ).AsQueryable ();
}

public interface ISecurable
{
    int Id { get; set; }
    bool CanRead { get; set; }
    bool CanWrite { get; set; }
    bool CanDelete { get; set; }
}

UserEntityAccess is a cross-reference table between a user and a business object record (i.e. an entity). Each record contains fields like “CanRead”, “CanWrite”, and “CanDelete”, and determines what a specific user can do with a specific record.

ISecurable is a marker interface that must be implemented by any LINQ-to-SQL domain class that needs to use this secured Get method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:37:51+00:00Added an answer on May 13, 2026 at 4:37 pm
    var projection = DataContext.GetTable<Foo>
                                .AsEnumerable()
                                .Select(f => f.SetRetrievalTimeAndReturnSelf());
    

    This will then perform the invocation of SetRetrievalTimeAndReturnSelf for each instance of Foo in DataContext.GetTable<Foo> when the IEnumerable<Foo> projection is iterated over.

    What do you need to know the time that object was yanked of the database for? That’s potentially smelly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class with a property that gets set by another class. Inside
I want to set a read-only attribute inside a class method. I have already
I have a class that has a property that I need to stub. I
I have a class called Property that I only need to display a few
I have a property within a class, that I need to iterate through all
I have a class with a ReadOnlyCollection property. I need to convert that ReadOnlyCollection
I have a class that needs to be initialized but it's namespaced like this:
I have a generic class that needs to limit an enum depending on the
I have a Base class that needs a Generic type. That can be either
I have a utility class that needs to work on a generic Class but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.