louthy / csharp-monad

Library of monads for C#
MIT License
464 stars 53 forks source link

Does Option work with Entity Framework? #7

Open ghost opened 9 years ago

ghost commented 9 years ago

Not sure if issues is the right place to ask a question. Please do tell me if that's not the case. I just wanted to know if "Option" works with LINQ for Entity Framework.

louthy commented 9 years ago

Hi @zyx3nzh7

I haven't tried. Have you tried and are experiencing problems?

ghost commented 9 years ago

No, but I can try and report back on Thursday.

ghost commented 9 years ago

I tried and it doesn't work since LINQ to Entity only supports some (primitive?) types like (Int32, String, int? and Guid) and Nullable. Maybe a few more but for Option an Exception is thrown at runtime. Unfortunately this makes this great library less useful for me.

louthy commented 9 years ago

Where do you wish to use the Option value? In the query expression or the select projection? (or both?)

louthy commented 9 years ago

Actually, if you can post an example query that'd help. I'm wondering how you're using the value? Perhaps there's some cunning that can be done by projecting to IEnumerable and doing an 'in'.

ghost commented 9 years ago

//relevant part in the model [Column("age")] public Option oAge { get; set; } //the code var db = new testContext(); var temp = db.TestTabelle.Where(x => x.oAge == null).

Entity Framework tries to translates the lamda function to SQL at runtime and fails. Unfortunately i have no clue how the translation works internally and how one could extend it.