• 0

Generic Constraint for a Record Type and MySQL EF Question


Question

First question,

Not sure if I can constrain this better,

let MapRecord<'t when 't : comparison and 't : equality and 't : not struct> =
/*OMITTED*/
this calls PreComputeRecordConstructor to create a record based on data ...

Second question,

AFAIK F# has no type provider that supports MySQL - only MS SQL.

Thus, if I want to do parsing on MySQL data the best solution is to,

1. Create a C# library with the generated EDMX file (database first)

2. Reference said library in F# code in use it

How sane does this sound? Is there a better solution?

Also, on the same topic as question 2,

let inline getId item = (^a : (member ID : int) item)
don't work in EF queries. EF actually sees the getId funct and does not recognize it throwing an error.

I thought that such code gets resolved and inlined into a direct .memberName call when compiled in IL?

4 answers to this question

Recommended Posts

  • 0

The SQLProvider supports MySQL, according to the project home page.

 

The way inline resolves static generic constraints is by - as the name implies - inlining: it won't work if you assign the function to a non-inline one.

  • 0
  On 15/07/2015 at 16:01, Andre S. said:

The SQLProvider supports MySQL, according to the project home page.

 

The way inline resolves static generic constraints is by - as the name implies - inlining: it won't work if you assign the function to a non-inline one.

Hmm. I am hesitant on trying that out as it is a 3rd party solution.

EDIT: I mean, would you use it or rely on a mutli-project multi-language setup instead?

I worked around by adding an interface to the generated classes and using 'a when 'a :> IFooBar - granted more code.

But I still don't get it, such code works just fine after the query is returned but

when using to filter output from a DbSet it fails at runtime with an EF error complaining that it doesn't support it.

Is it just not possible to use inlined generic functions with EF's _ DbSet query?

This works because queryDb returns the list result of an executed query and then inlined func is applied,

    let inline private getCode item = (^a : (member Code : _) item)
    let inline private getType item = (^a : (member Type : _) item)
    let inline private getDescription item = (^a : (member Description : _) item)

    let inline private getCodeInfo item = getCode item, getDescription item
    let inline private getTypeInfo item = getType item, getDescription item

    let inline private xInfo (table : FooBarEntities -> _ DbSet) f = 
        queryDb (fun db -> table db) |> List.map f |> Map.ofList

    let inline private codeInfo table = xInfo table getCodeInfo
    let inline private typeInfo table = xInfo table getTypeInfo
EDIT:

Actually I can't see to do something like,

        query {
            for item in set do
            where (filter item) //(filter item)
            select item
        }
at all. Seems this is completely different than C# .Where(filter) function.

I am not sure how to approach this. I will try to use C#' Where with an Expression in F# instead.

EDIT: ###### that I will write these extensions methods in C# - can't figure out the heads and taiils of why EF complains about Invoke

Edited by _Alexander
  • 0
  Quote
Hmm. I am hesitant on trying that out as it is a 3rd party solution.

EDIT: I mean, would you use it or rely on a mutli-project multi-language setup instead?

My guess is that working with a type provider should be less painful than EF. But there are several options, perhaps the documentation here can answer some of your woes with LINQ etc.:

http://fsharp.org/guides/data-access/#sql-data-access

 

To be honest, I know very little about EF, SQL and type providers, so unless there are F# afficionados other than me here, I would suggest you ask the question on Stackoverflow. F#'s community is very supportive, but not well represented here.

  • 0

If anyone is wondering on a record constraint, I got this by looking at the metadata from a C# project,

public sealed class TestRecord : IEquatable<TestRecord>, IStructuralEquatable, IComparable<TestRecord>, IComparable, IStructuralComparable
so F# constraint would look like,

    let RecordMap<'record 
        when 'record :> IEquatable<'record> 
        and 'record :> IStructuralEquatable 
        and 'record :> IComparable<'record>
        and 'record :> IComparable
        and 'record :> IStructuralComparable
        and 'record : comparison 
        and 'record : equality 
        and 'record : not struct> =
I think I figured out the EF.

EF uses reflection and Expressions to determine what query to build - the way I was doing it was NOT an F# specific issue - same issue happens in C#.

I hope Microsoft will expand F# to support ASP.NET, WPF, and refactoring in the future. Good language - horrid support.

This topic is now closed to further replies.
  • Posts

    • Meta's Superintelligence team staffed by 50% Chinese talent, 40% ex-OpenAI by Hamid Ganji Mark Zuckerberg's latest big bet at Meta involves building a team of the best AI superstars in the market to lead the so-called Superintelligence Labs. The goal of this team is to develop AI models that will ultimately lead to Artificial General Intelligence (AGI). AGI refers to an AI model with capabilities comparable to, or even beyond, those of the human brain. Achieving human-level cognitive abilities with an AI model requires substantial investments, as well as hiring the best talent to build such a system. That's why Meta is throwing hundreds of millions of dollars at AI researchers from OpenAI, Apple, and other companies to recruit them for its Superintelligence team. A user on X has now shared a spreadsheet that provides us with some unique insights into Meta's Superintelligence team and the origins of its 44 employees. The leaker claims this information comes from an anonymous Meta employee. The listing claims that 50 percent of the staff at the Superintelligence team are from China, which demonstrates the significant role of Chinese or Chinese-origin researchers in Met's AI efforts. Additionally, 75 percent of these staff hold PhDs, and 70 percent of them work as researchers. Interestingly, 40 percent of the staff are ex-OpenAI employees whom Mark Zuckerberg poached from the maker of ChatGPT. Additionally, 20 percent of Meta's Superintelligence team members come from Google DeepMind, and another 15 percent come from Scale AI, a startup that Meta recently acquired in a $15 billion deal. Another interesting point is that 75 percent of the Superintelligence team are first-generation immigrants. The leaker claims that each of these employees is now earning between $10 million and $100 million per year, although Meta still needs to confirm these substantial figures. However, it has already been reported that Meta is offering up to $100 million in signup bonuses to poach the best AI talent from OpenAI and other rivals. The revelation that half of Meta's Superintelligence team consists of Chinese nationals could trigger concerns within the Trump administration and Congress.
    • From a quick Google it seems 6GHz is optional on 802.11be. Ubiquiti has one, Unifi U7 Lite.
    • Disagreed, I feel it’s going somewhere and his role served a purpose - and moreover with maybe what 10 mins of screen time - he had a bit of character development also.
    • This is the Superman film I had been waiting for. The tone was fine, yes a little more “fun” than previous outings but a lot of that came from supporting characters. Krypto was well handled, and somehow managed to not be an annoying distraction and actually a valid part of the story. Hoult was GREAT as Luthor. Genuinely so happy that this wasn’t crap. I personally enjoyed Superman Returns, despite its flaws (tried too much to hide behind the older movies, had no real fight to Superman). I enjoyed the Man Of Steel movies despite their flaws (totally that is NOT Superman). But this - this is the film I had wanted. In the UK we are far more reserved in cinemas than Americans. It’s rare that there is the whooping and hollering that we have seen from videos of US theatres, so when I say that the audience clapped at the end of this - it’s quite a big deal. As for all this “Superman has gone woke” BS - he is freaking Superman and if at any point in that movie you found yourself pooh-pooing his actions, you are just - you’re aligning your thinking with the problems and not the solutions. I adore how the movie addressed the modern world through thinly veiled allegory (Israel, online bots, perceptions of people, how they change on a dime) - that is maybe one of the greatest strengths of  comics, they rarely pull punches with that sort of thing, and look, THIS IS SUPERMAN, he’s meant to be the global boyscout and that is a strength and where he falls down sometimes, that’s just who he is and who he is meant to be. I also am glad there was no reference to the worldwide joke that is “Truth, Justice and the American way”. I can understand the comment suggesting this film was a little too “fun” or “whimsical”, but I’d urge a rewatch of the Donner Superman. It was very much a flawed masterpiece and its subsequent sequel had too many jokes that didn’t land. While there was a lot of James Gunn in this movie, I feel he pulled it back significantly, it wasn’t Guardians and moreover a lot of the fun came from supporting roles.
    • People do it everywhere. Should be legal to be allowed to bitch slap people who put their phone on speaker in public places
  • Recent Achievements

    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      205
    4. 4
      Xenon
      140
    5. 5
      +FloatingFatMan
      115
  • Tell a friend

    Love Neowin? Tell a friend!