开发者

Why is F# member not found when used in subclass

I have a base type that I want to inherit from, for all my DAO objects, but this member gets the error further down about not being defined:

type BaseDAO() =
    member v.ExecNonQuery2(conn)(sqlStr) =
        let comm = new MySqlCommand(sqlStr, conn, CommandTimeout = 10)
        comm.ExecuteNonQuery |> ignore
        comm.Dispose |> ignore

I inherit in this t开发者_开发问答ype:

type CreateDatabase() =
    inherit BaseDAO() 

    member private self.createDatabase(conn) =
        self.ExecNonQuery2 conn "DROP DATABASE IF EXISTS restaurant"

This is what I see when my script runs in the interactive shell:

--> Referenced 'C:\Program Files\MySQL\MySQL Connector Net 6.2.3\Assemblies\MySql.Data.dll'

[Loading C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\BaseDAO.fs]

namespace FSI_0106.RestaurantServiceDAO
  type BaseDAO =
    class
      new : unit -> BaseDAO
      member
        ExecNonQuery2 : conn:MySql.Data.MySqlClient.MySqlConnection ->
                          sqlStr:string -> unit
      member execNonQuery : sqlStr:string -> unit
      member
        execQuery : sqlStr:string *
                    selectFunc:(MySql.Data.MySqlClient.MySqlDataReader ->
                                  'a list) -> 'a list
      member f : x:obj -> string
      member Conn : MySql.Data.MySqlClient.MySqlConnection
    end

[Loading C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\CreateDatabase.fs]


C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\CreateDatabase.fs(56,14): error FS0039: The field, constructor or member 'ExecNonQuery2' is not defined

I am curious what I am doing wrong.

I have tried not inheriting, and just instantiating the BaseDAO type in the function, but I get the same error.

I started on this path because I had a property that had the same error, so it seems there may be a problem with how I am defining my BaseDAO type, but it compiles with no error, which further confuses me about this problem.


It looks like maybe you are #loading individual files, and maybe you have a bit of stuff in your history, and the class you're inheriting is in another namespace/module and you're inheriting some older version without that member?

Reset your fsi session and start over, or put it in .fs files to diagnose if anything is really wrong, but I think the code is ok and the issue is something with how you're interacting with FSI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜