Getting "value not defined" on type inheritance

I do not see what I am doing wrong, as the files are in the correct order. In this case, it is:

  • BaseDAO.fs
  • CreateDatabase.fs

They are in the same namespace, but even when I used them in different modules and opened the module in CreateDatabasethe same error.

Error:

Error   1   The value or constructor 'execNonQuery' is not defined  

I am trying to inherit BaseDAOand use an element that will be shared across multiple files, and I do not understand why I received the error above.

namespace RestaurantServiceDAO

open MySql.Data.MySqlClient

type BaseDAO() =
    let connString = @"Server=localhost;Database=mysql;Uid=root;Pwd=$$$$;"
    let conn = new  MySqlConnection(connString)

    member self.execNonQuery(sqlStr) =
        conn.Open()
        let comm = new MySqlCommand(sqlStr, conn, CommandTimeout = 10)
        comm.ExecuteNonQuery |> ignore
        comm.Dispose |> ignore

The type inheriting here is execNonQuerynot defined.

namespace RestaurantServiceDAO

open MySql.Data.MySqlClient

type CreateDatabase() =
    inherit BaseDAO()

    let createRestaurantTable conn =
        execNonQuery "CREATE TABLE restaurant(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), cur_timestamp TIMESTAMP(8))"
+3
source share
1 answer

F # ( , ) - - . base. :

type CreateDatabase() = 
    inherit BaseDAO() 
    let createRestaurantTable conn = 
        base.execNonQuery "..."

[EDIT] , createRestaurantTable member - , let ( ). , F # caputring base , . :

type CreateDatabase() = 
    inherit BaseDAO() 
    private member x.createRestaurantTable conn = 
        x.execNonQuery "..."

[/EDIT]

as self ( member self.Foo() = .. . :

type CreateDatabase() as self = 
    inherit BaseDAO() 
    let createRestaurantTable conn = 
        self.execNonQuery "..."

base, ( ).

+5

Source: https://habr.com/ru/post/1744718/


All Articles