0

This is the first time I have attempted to join information from one database to the other. I have a accounting database and a regular site database. Trying to keep them separate. I have a page that shows Transactions but am getting the information for a few of the columns from the regular database by way of Id's. Below is my Model. I am showing nothing in the fields for the items in the other database.

    public class Transaction
{
    [Key]
    public Guid TransactionId { get; set; }
    public string Description { get; set; }
    public int? CompanyId { get; set; }
    public Guid? VendorId { get; set; }
    public string InCheckNumber { get; set; }
    public string OutCheckNumber { get; set; }
    public string InvoiceNumber { get; set; }
    public string PurchaseOrderNumber { get; set; }
    public Guid LedgerAccountId { get; set; }
    public decimal? DebitAmount { get; set; }
    public decimal? CreditAmount { get; set; }
    public DateTime TransactionDate { get; set; }
    public string ModifiedBy { get; set; }
    public DateTime? ModifiedDate { get; set; }
    public string SavedDocument { get; set; }
    public DateTime CreatedDate { get; set; }
    public string CreatedBy { get; set; }
    public bool IsCredit { get; set; }
    public bool IsDebit { get; set; }
    public Guid Type { get; set; } 

    [ForeignKey("LedgerAccountId")]
    public LedgerAccount LedgerAccount { get; set; }
    [ForeignKey("CompanyId")]
    public CompanyNames Company { get; set; }
    [ForeignKey("VendorId")]
    public Vendors Vendor { get; set; }

}

I have added the 'using' of the General.Entities to this model. Is there something else i need to add for this?

Thanks in advance.

UPDATE: See Question - Link to answer of question

5
  • 1
    Your question is unclear. Are you encountering an error? Or is your code not giving you the results you expect? Also, are these two different tables or two different database instances? Commented Jan 7, 2021 at 20:39
  • it seems you are saying you use your DTO as view models. There is a specific pattern for this, ViewModels. Create another model with the properties that you need from whichever datatables. Commented Jan 7, 2021 at 20:50
  • I am not getting an Error, the fields on the page are just blank. For instance CompanyId is in an accounting table from Accounting DB and CompanyName is in Company Table in the General DB. Commented Jan 7, 2021 at 20:50
  • @LinkedListT I do use ViewModels, I did not for this. If this will clear the area up I will create one. I am assuming the ViewModel will look Identical to the model above, correct? Commented Jan 7, 2021 at 20:52
  • correct @ScottPurtan. But you should only use the necessary properties for the ViewModel. Even if it is going to populate 2 different entities. Commented Jan 8, 2021 at 14:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.