2

I have 2 projects in a solution: a C# class library and an F# library.

The C# library has the following class:

using System;

namespace TestFSharpDataLayer.Domain
{
    public class TestData
    {
        public Guid Id { get; set; }
        public string Nickname { get; set; }
        public DateTime StartDate { get; set; }
        public bool Active { get; set; }
        public byte[] Fingerprint { get; set; }
        public char Prefix { get; set; }
        public int Multiplier { get; set; }
    }
}

I'm writing a module in the F# library to get data from a MSSQL database, and I want to make my List function to return an array of TestDataobjects. I'm using SQLProvider in the F# library.

Module code:

namespace TestFSharpDataLayer.Infrastructure

module PersonasRepository = 
    open FSharp.Data.Sql
    open FSharp.Data.Sql.Common
    open TestFSharpDataLayer.Domain

    type private sql = SqlDataProvider<DatabaseProviderTypes.MSSQLSERVER,"server=(localdb)\MSSQLLocalDB;Database=Test;Trusted_Connection=true;">

    let private context = sql.GetDataContext()

    let private ListarInternal (pagina : int) =
        query {
            for c in context.Dbo.TestData do
            sortBy (c.GetColumn "Nickname")
            skip ((pagina - 1) * 15)
            take 15
            select c
        } 
        |> Seq.map EntityToTestData
        |> Seq.toArray

    let private EntityToTestData (entity : sql.dataContext.``dbo.test_dataEntity``) : TestData =
        new TestData(Id = entity["Id"], Nickname = entity["Nickname"])

    let Listar (pagina : int) = 
        match pagina with 
        | t when t > 0 -> ListarInternal(pagina)
        | _ -> null

Problem is, I can't get the module to recognize the TestData class. C# library is referenced in the F# library, but the open TestFSharpDataLayer.Domain sentence is not recognized by Intellisense and it also throws a compile-time error (TestFSharpDataLayer namespace not defined). Visual Studio shows no warnings.

What am I doing wrong?

Léster
  • 1,177
  • 1
  • 17
  • 39
  • 1
    If you build the project are there any warnings? These can often indicate a problem regarding the reference (e.g. is one .NET Core/Framework?). Probably worth adding that info to the Q – DaveShaw Oct 02 '19 at 19:01
  • Thank you, edited. – Léster Oct 02 '19 at 19:21
  • 2
    Is it possible you're missing a reference to the C# library in question in your F# project? – VoronoiPotato Oct 02 '19 at 19:31
  • 1
    I wasn't... but removing the reference, re-adding it and recompiling solved the problem. I'm still wondering what was the problem. – Léster Oct 02 '19 at 22:11
  • Hi, thanks for your sharing and please mark your comment as answer and that will help other community members who easier search this useful information, it just a reminder :) – LoLance Oct 08 '19 at 03:18

0 Answers0