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 7828165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:14:16+00:00 2026-06-02T10:14:16+00:00

I’m trying to run a query on a very simple table but I’m not

  • 0

I’m trying to run a query on a very simple table but I’m not getting to any result. The table contains an action log with the following columns:

  • ID
  • ActionTypeID (create, edit or delete)
  • EntryID (the id of the created/edited/or deleted entry)
  • TableName (where the action was committed)
  • ControlName
  • Person (who committed the action. nt-user with department)
  • Date

What I wanted to get is a list of all EntryIDs with ActionTypeID == 1 and Person (department) ending with one of a dynamic list of strings. The Problem is that only the first action for one EntryID in the action log should be checked to match one of these departments.

I know this sounds pretty weird. This may result from my bad english and from the database designing disability of my former colleague. I don’t know which is worse.

My attempt to get the result I wanted is this:

var predicate = PredicateBuilder.False<ActionLog>();
var pOuter = PredicateBuilder.True<ActionLog>();

pOuter = pOuter.And(h => h.TableName.ToUpper() == "Contact".ToUpper());
pOuter = pOuter.And(h => h.ActionType.ID == 1);

foreach (var dep in b.DepartmentList)
{
    predicate = predicate.Or(x => x.Person.EndsWith("/" + dep.Value));
}

pOuter = pOuter.And(predicate.Expand());

mContactIDs = (from h in db.ActionLog
orderby h.Date
select h).AsExpandable().Where(pOuter).Select(x => x.EntryID).Distinct().ToList();

But this returns me all entries where the ‘Person’ ends with the selected departments. I just want to check the first entry with this EntryID.

I hope anyone understands what I’m trying to translate from confused german to weird english.

oh- by the way, it’s .Net 3.5

EDIT
I think I have some problems finding the right explanation – I’ll try it with some dummy data.

ID | ActionTypeID | EntryID | TableName  | ControlName | Person             | Date
----------------------------------------------------------------------------------------
1  | 1            | 3       | 'Contacts' | NULL        | 'xxxx/department1' | 04/11/2012
2  | 1            | 3       | 'Contacts' | NULL        | 'yyyy/department2' | 04/11/2012
3  | 1            | 5       | 'Contacts' | NULL        | 'yyyy/department2' | 04/13/2012
4  | 1            | 14      | 'Contacts' | NULL        | 'zzzz/department1' | 04/16/2012

In my example i would be searching for log entries with “Person ends with ‘/department2’ created the first occurrence of a new EntryID”, “TableName == ‘Contacts'” and “ActionTypeID == 1”. The result I want to receive would be (only EntryIDs) 5, as this is the only entry where a user of department2 has been the first one Inserting this EntryID with ActionTypeID 1. I know this is stupid and if I had designed the database I wouldn’t have done it this way, but now I have to deal with it. If the quantity of departments to query would not be dynamic I would use this snippet:

IQueryable<ActionLog> log = db.ActionLog;
mContactIDs = (from k in db.Contacts
    where (from h in log
        where h.TableName == "Contacts"
        && h.EntryID == k.ID
        && h.ActionType.ID == 1
        orderby h.Date
        select h).FirstOrDefault().Person.EndsWith("/" + b.Department)
    select k.ID).ToList();

But I don’t know how to connect those dynamic departments with the stupid design (and multiple ActionTypeID 1 (create) for one entry. I don’t even know why the application saves this)

Thank you, Ben.

  • 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-06-02T10:14:17+00:00Added an answer on June 2, 2026 at 10:14 am

    I decided to use Entity SQL instead.

            List<int> mContactIDs = new List<int>();
            using (var db = new Entities())
            {
                string queryString = @"
                                    SELECT  
                                        VALUE H.EntryID
                                    FROM    
                                        Entities.ActionLog AS H
                                    WHERE 
                                        H.ID IN (
                                            SELECT VALUE TOP (1) Hi.ID
                                            FROM Entities.ActionLog AS Hi
                                            WHERE Hi.ActionType.ID = 1
                                            AND Hi.TableName = 'Kontakt'
                                            AND Hi.EntryID = H.EntryID
                                            ORDER BY Hi.Date    
                                        )
                                    {0}
                                    GROUP BY H.EntryID";
    
                List<string> lDepartments = new List<string>();
                foreach (var dep in b.DepartmentList)
                {
                    lDepartments.Add(string.Format(" H.Person LIKE '%{0}' ", dep.Value));
                }
    
                string sDepartmentQuery = string.Empty;
                if (lDepartments.Count > 0)
                {
                    sDepartmentQuery = string.Format(" AND ({0}) ", string.Join(" OR ", lDepartments.ToArray()));
                }
    
                var result = db.CreateQuery<int>(string.Format(queryString, sDepartmentQuery));
                if (result != null && result.Count() > 0)
                {
                    mContactIDs = result.ToList();
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.