While building a F# ASP.NET MVC 4 app with the C#/F# template from the VisualStudio gallery, a doubt assaulted me. I have the following model class:
同时构建一个f# ASP。来自VisualStudio gallery的c# / f#模板的NET MVC 4应用程序,让我怀疑。我有以下模型类:
namespace MyApp.Models
open System
open System.ComponentModel.DataAnnotations
open System.Collections.Generic
type Product() =
[<Key>] member val Id = Guid.NewGuid() with get, set
[<Required>] member val Name = "" with get, set
member val Iban = "" with get, set
member val Categories = new List<ProductCategory>() with get, set
As F# has its own types, in cases like the last one, should we use an F# equivalent (an F# list, a sequence...) or should we use System types? If so, what would be the reasoning?
由于f#有自己的类型,在类似于上一个的情况下,我们应该使用一个f#等价的(一个f#列表,一个序列…)还是应该使用系统类型?如果是这样,那么推理是什么?
Thank you very much!
非常感谢!
1 个解决方案
#1
2
As a rule of thumb, I'd go by what language(s) is(are) consuming your models. If it's F# all the way down, go for it. If it's mixed you'll need to be more judicious. As an aside, Option<>
and List<>
play pretty well with C# (though I find I need type aliases to "clean up" some of the code). Also an F# sequence is just an IEnumerable<>
, so no worries there. Also, there's nothing wrong with using arrays and ResizeArray<>
(aka System.Collections.Generic.List<>
) in F# -- you just have to be mindful of state mutation.
作为一个经验法则,我将按照使用何种语言来使用您的模型。如果它是f#一直下去,那就试试吧。如果是混合的,你需要更加明智。顺便提一下,选项<>和List<>在c#上运行得很好(尽管我发现我需要类型别名来“清理”一些代码)。f#序列也是IEnumerable<>,所以不用担心。此外,在f#中使用数组和ResizeArray<>(即System.Collections.Generic.List<>)并没有错——您只需注意状态突变。
#1
2
As a rule of thumb, I'd go by what language(s) is(are) consuming your models. If it's F# all the way down, go for it. If it's mixed you'll need to be more judicious. As an aside, Option<>
and List<>
play pretty well with C# (though I find I need type aliases to "clean up" some of the code). Also an F# sequence is just an IEnumerable<>
, so no worries there. Also, there's nothing wrong with using arrays and ResizeArray<>
(aka System.Collections.Generic.List<>
) in F# -- you just have to be mindful of state mutation.
作为一个经验法则,我将按照使用何种语言来使用您的模型。如果它是f#一直下去,那就试试吧。如果是混合的,你需要更加明智。顺便提一下,选项<>和List<>在c#上运行得很好(尽管我发现我需要类型别名来“清理”一些代码)。f#序列也是IEnumerable<>,所以不用担心。此外,在f#中使用数组和ResizeArray<>(即System.Collections.Generic.List<>)并没有错——您只需注意状态突变。