Entity Framework Code First CTP5:如何定义非原始类型
我首先测试 CTP5 的实体框架代码,我遇到了这个问题 我有一个具有 Uri (System.Uri) 类型属性的类,但它看起来无法自动识别如何存储该属性,因此我收到一个错误,例如
Problem in mapping fragments starting at line 23:No mapping specified for properties WebPage.Uri in Set WebPage
How can i Tell the model to map the Uri to例如,带有 uri 的 url 的 varchar?
I'm testing the CTP5 for entity framwork code first, and i've run into this problem
I've got a class that has a property of type Uri (System.Uri), but it looks like it's unable to automatically identify how to store that, so i get an error like
Problem in mapping fragments starting at line 23:No mapping specified for properties WebPage.Uri in Set WebPage
How can i tell the model to map the Uri to a varchar, for example, with the url of the uri??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际的 POCO 模型必须绑定到原始类型。您可以使用复杂类型绑定,例如:
如果确实需要,则在实际对象中引用此复杂类型作为 Uri 引用。然后,您的映射将以字符串形式引用实际值的属性。最后一个选项是创建从 URI 到字符串的自定义映射(反之亦然)以供 EF 引擎使用。但是,我不建议这样做。实际的数据库属性是 varchar 或 nvarchar 类型,而不是 URI。因此 EF 不知道 URI 是什么。
The actual POCO model has to bind to primitive types. You can use a complex type binding such as:
And in your actual object reference this complex type as the Uri reference if you absolutely need to. Your mapping would then reference the property for the actual value as a String. The final option is to create a custom mapping from URI to string and vice versa for the EF engine to use. However, I would not advise this. The actual database property is of type varchar or nvarchar, not URI. Thus EF doesn't know what a URI is.