fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
579 stars 146 forks source link

When using context schema path the generated schema file is not correct #835

Closed halcwb closed 2 hours ago

halcwb commented 4 hours ago

Describe the bug When trying to use the ContextSchemaPath the build will fails with: The type 'dbo.UsersEntity' does not define the field, constructor or member 'UserId'. In fact, this happens for all generated types.

First I didn't use the context schema path. When trying to use this feature, the schema files are generated but they do not contain any column names and seem only to list tables.

As an example of a generated schema file:

{"Columns@":[],"Individuals@":[],"IsOffline@":true,"Packages@":[],"PrimaryKeys@":[],"Relationships@":[],"SprocsParams@":[],"Sprocs@":[],"Tables@":[{"Key":"dbo.FreeTextSignals","Value":{"Name@":"FreeTextSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Signals","Value":{"Name@":"Signals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.EventSignals","Value":{"Name@":"EventSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.PendingOrders","Value":{"Name@":"PendingOrders","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.OrderEntry","Value":{"Name@":"OrderEntry","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.PendingRangeSignals","Value":{"Name@":"PendingRangeSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.ParametersCategories","Value":{"Name@":"ParametersCategories","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.PatientLogs","Value":{"Name@":"PatientLogs","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Patients","Value":{"Name@":"Patients","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Micro_Microbes","Value":{"Name@":"Micro_Microbes","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Integration_MSG_Info","Value":{"Name@":"Integration_MSG_Info","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Units","Value":{"Name@":"Units","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.ORD_StandardTimes","Value":{"Name@":"ORD_StandardTimes","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.t_OrderType","Value":{"Name@":"t_OrderType","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Parameters","Value":{"Name@":"Parameters","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Transfer","Value":{"Name@":"Transfer","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Transport","Value":{"Name@":"Transport","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Users","Value":{"Name@":"Users","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.TextSignals","Value":{"Name@":"TextSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.ParametersText","Value":{"Name@":"ParametersText","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Beds","Value":{"Name@":"Beds","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Micro_Specimen","Value":{"Name@":"Micro_Specimen","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.DateTimeSignals","Value":{"Name@":"DateTimeSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.LogicalUnits","Value":{"Name@":"LogicalUnits","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Micro_GroupMaterial","Value":{"Name@":"Micro_GroupMaterial","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Micro_Result","Value":{"Name@":"Micro_Result","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Orders_MedicationActiveComponents","Value":{"Name@":"Orders_MedicationActiveComponents","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.RangeSignals","Value":{"Name@":"RangeSignals","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.PatientOwnerships","Value":{"Name@":"PatientOwnerships","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.DripUnits","Value":{"Name@":"DripUnits","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Micro_Material","Value":{"Name@":"Micro_Material","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Orders_Routes","Value":{"Name@":"Orders_Routes","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.OrderCategories","Value":{"Name@":"OrderCategories","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.Orders_Locations","Value":{"Name@":"Orders_Locations","Schema@":"dbo","Type@":"base table"}},{"Key":"dbo.PlannedOrders","Value":{"Name@":"PlannedOrders","Schema@":"dbo","Type@":"base table"}}]}

This file should be much larger.

Using MSSQL.

Tried:

This works:

So it seems that you need to first:

  1. Successfully build the project
  2. Set a path to the ContextSchemaPath
  3. Use ctx.Design Time Commands.SaveContextSchema ` only to trigger the build of the schema file.

If there is no schema file nothing happens until you type in step 3.

I completely didn't get this at first. I thought this was done at compile time.

Environment: .NET SDK: Version: 9.0.100 Commit: 59db016f11 Workload version: 9.0.100-manifests.3068a692 MSBuild version: 17.12.7+5b8665660

Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100\

Thorium commented 4 hours ago

It’s lazy, it won’t save all the database, just the columns you use.

Thorium commented 4 hours ago

Which database you are using?

halcwb commented 4 hours ago

It’s lazy, it won’t save all the database, just the columns you use.

Then it is extremely lazy as it doesn't add any columns at all :-)

halcwb commented 4 hours ago

Which database you are using?

I have added the information and am investigating this.

halcwb commented 3 hours ago

Having fixed this issue I was hoping that offline builds were possible (https://github.com/fsprojects/SQLProvider/issues/644#issuecomment-785677924)

However, when trying an offline build, this isn't possible, also with the schema files present.

halcwb commented 2 hours ago

After making all the mistakes that were made in the past issues. I finally got this working. I will try and create a blog about using SQLProvider, because I think there quite some caveats (at least I ran into).

@Thorium Thanks! (not sarcastically but well meant).

Thorium commented 1 hour ago

If you use MS SQL Server then I recommend the SSDT (sqlproj/dacpac) version. But if you use something else like Postgres or MySQL then I guess SaveContextSchema is your way to do offline builds.