skip to Main Content

I am designing an online store (ASP.NET Core 6) for an accounting software (C# Winforms).

I started this using ASP.NET Core and Razor pages.

I am new and inexperienced in this field. The accounting software has many tables in SQL Server, and these tables are related to each other.
I try to make model only the tables I need for my project.

But when communicating with the desired table, get the following error 🙁 .

Invalid column name ‘MobileNo’.
Invalid column name ‘BankAccountNumber’.
Invalid column name ‘BankBranch’.
Invalid column name ‘BirthDate’.
Invalid column name ‘BrithLocation’.
….

I know that this error is due to the relationships of the desired table with other tables.

Because in other similar cases, when I defined the second table and the relationship, this error was resolved.

....
public string UserID { get; set; }
....
[ForeignKey(nameof(UserID))]
public virtual SalCustomer users { get; set; }
....

but I came across a table that is very related to other tables (tables that are not needed).

I feel it is not right to create extra models and I don’t like to add them to my project.

Is there a way in EF to ignore relationships? Without causing a problem in the accounting software?

Because there is no need for these relationships in my project.

For example:

the relationship between the customer table and the tax document table or the Cheque table and… there are too many tables.

Is it better to create all the tables in my project even though I don’t need them?

An example of the code that generates this error.

var accPerson = _context.AccPerson.SingleOrDefault(c => c.mobileNo == SD.userPh1);

I apologize for my terrible English and thank you in advance for your valuable comments.

i read this post
but i think that the relationships will be completely removed and this may cause problems in the accounting software.
I can’t make any changes to the database.
Because many companies and software are using this database.

2

Answers


  1. The right choice could be to create an EF Project Database first. Visual Studio will generate the models for You. Because You cannot update database rows ignoring relationships: which values would You put in foreign keys properties?

    Login or Signup to reply.
  2. When using Ef core database first approach, you can specify the tables that you want to generate.

    Scaffold-DbContext 'Connection string' Microsoft.EntityFrameworkCore.SqlServer -Tables Customer, Purchases, Accounts, Contracts
    

    more information on scaffolding

    If you want more control you can learn how T4 templates work (might be a bit complicated if you are a beginner)

    Using T4 templates for reverse engineering

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search