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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:26:24+00:00 2026-06-17T23:26:24+00:00

I have Document class: public class Document { public int FromCompanyId { get; set;

  • 0

I have Document class:

public class Document
{
        public int FromCompanyId { get; set; }
        public int ToCompanyId { get; set; }
        public string DocumentText { get; set; }
}

When any Company sends Document to others, I saved their Id‘s. Shortly I have many pairs of ID’s:

1, 2  //  Company which has Id=1 sent document to Company which has Id=2.
1, 3  //  Company which has Id=1 sent document to Company which has Id=3.
4, 3  //  Company which has Id=4 sent document to Company which has Id=3 etc.
2, 1  
4, 3  
4, 5  
5, 4  
5, 5  
4, 5  
3, 1 

I want to make any Company manage only its own documents. Sent and Received. How can I get documents by Company Id? Or anybody can give another advice.

So, when id = ToCompanyId (any Company sent document to this Company) I want to group by FromCompanyId and when id = FromCompanyId (this Company sent document to other Company) I want to group by ToCompanyId.

This looks like facebook messages. When I cross my messages, I see my all dialogues by Id of other users. In my application I want to see documents by Id of other companies.

This works right only id = FromCompanyId.

GetDocumentsByCompanyId(int Id)
{
...
var myDocs= MyDatabaseContext.Documents.Where(e => e.FromCompanyId == Id|| e.ToCompanyId == Id);

var docGroups = from m in myDocs
                group m by m.ToCompanyId
                into g select new { ToCompanyIdKey = g.Key, betweenDocs = g };
...

}

Sorry for bad English.

  • 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-17T23:26:25+00:00Added an answer on June 17, 2026 at 11:26 pm

    You can use the following code.
    It simply uses the conditional operator to find out which is the ID of the other company. This information is than used to group the documents.

    var myDocs = MyDatabaseContext.Documents
                                  .Where(e => e.FromCompanyId == Id ||
                                              e.ToCompanyId == Id)
                                  .Select(x => new { OtherCompanyId
                                                       = (x.FromCompanyId == Id) ? 
                                                          x.ToCompanyId : 
                                                          x.FromCompanyId,
                                                     Document = x });
    
    var docGroups = from m in myDocs
                    group m by m.OtherCompanyId into g
                    select new { ToCompanyIdKey = g.Key,
                                 BetweenDocs = g.Select(x => x.Document) };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class... class Document { public int GroupID { get; set; }
i have an abstract class public abstract class Document { public int DocumentID {get;
I have the following object: public class MyClass { public int Id { get;
public class DayData { public string _id {get;set;} public string Data {get;set;} public HourData
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have something that looks like the following document structure: public class Document {
I have a code like this: [Serializable] public class A { public int X
I have the following: public abstract class EntityBase { [Key] public int Id {
I have a set of documents that represent some workitems: public class WorkItem {

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.