.NET CodeFirst Entity Framework:uniqueidentifier作为TPH映射中的collumn鉴别器 [英] .NET CodeFirst Entity Framework: uniqueidentifier as collumn discriminator in TPH mapping

查看:96
本文介绍了.NET CodeFirst Entity Framework:uniqueidentifier作为TPH映射中的collumn鉴别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用uniqueidentifier collumn作为对象的TPH映射的鉴别器。

流畅的代码配置如下:

 Map< ImplementationDocument>(m = >  m.Requires(  DocumentType_ID)。HasValue(Guid.Parse(  A83EC21A-5661-462E-9539 -F889F3BA2B5B)))。 
地图< WarrantyDocument>(m = > m.Requires( DocumentType_ID)。HasValue(Guid.Parse( E4A8F66F-E82D-E011 -9483-00151710A8AC)))。
地图< InvoiceDocument>(m = > m.Requires( DocumentType_ID)。HasValue(Guid.Parse( 821BC287-E82D-E011 -9483-00151710A8AC)));



因此我得到映射异常:

错误2016:无法在成员的值上指定条件' DocumentType_ID。类型'SqlServer.uniqueidentifier'不支持值条件。



是否意味着这种映射方案完全不可能?

解决方案

好的,所以正确的配置如下,我应该简单地给出字符串值而不是解析guid:

 Map< ImplementationDocument>(m = > m.Requires(  DocumentType_ID)。HasValue(  A83EC21A-5661-462E-9539-F889F3BA2B5B))。 
Map< WarrantyDocument>(m => m.Requires( DocumentType_ID)。 HasValue( E4A8F66F-E82D-E011-9483-00151710A8AC))。
Map< InvoiceDocument>(m => m.Requires( DocumentType_ID)。 HasValue( 821BC287-E82D-E011-9483-00151710A8AC));


Hello, I'm trying to use uniqueidentifier collumn as discriminator for TPH mapping of objects.
Fluent code configuration is like this:

Map<ImplementationDocument>(m => m.Requires("DocumentType_ID").HasValue(Guid.Parse("A83EC21A-5661-462E-9539-F889F3BA2B5B"))).
           Map<WarrantyDocument>(m => m.Requires("DocumentType_ID").HasValue(Guid.Parse("E4A8F66F-E82D-E011-9483-00151710A8AC"))).
           Map<InvoiceDocument>(m => m.Requires("DocumentType_ID").HasValue(Guid.Parse("821BC287-E82D-E011-9483-00151710A8AC")));


As a result I'm getting mapping exception:
error 2016: Condition can not be specified on values of member 'DocumentType_ID'. Value conditions are not supported for type 'SqlServer.uniqueidentifier'.

Does it mean that this mapping scenario is totally impossible?

解决方案

Ok, so the right configuration is following,I should simply give string values instead of parsed guid:

Map<ImplementationDocument>(m => m.Requires("DocumentType_ID").HasValue("A83EC21A-5661-462E-9539-F889F3BA2B5B")).
            Map<WarrantyDocument>(m => m.Requires("DocumentType_ID").HasValue("E4A8F66F-E82D-E011-9483-00151710A8AC")).
            Map<InvoiceDocument>(m => m.Requires("DocumentType_ID").HasValue("821BC287-E82D-E011-9483-00151710A8AC"));


这篇关于.NET CodeFirst Entity Framework:uniqueidentifier作为TPH映射中的collumn鉴别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆