当鉴别器列有点时TPH [英] TPH when the discriminator column is a bit

查看:65
本文介绍了当鉴别器列有点时TPH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您的鉴别器列是位字段时,CTP5中是否可以执行TPH。如果是,那么我该如何指定。例如,鉴别器列上的HasValue接受storevalue,但无法指定该列的数据类型。
 在下面的示例中,Discontinued属性的存储值为1或0但是当我查看首先生成哪个代码的edmx文件时,它会自动将Discontinued列作为SSDL上的字符串。我该怎么改变?




modelBuilder.Entity< Product >()


               
.Map(mc =>


                
{


                    
mc.Requires(" Discontinued" ) .HasValue(" 1" );


        ;        
})


               
.Map< DiscontionuedProduct >(mc =>


      ;          
{


     ;               
mc.Requires("已停止使用")。HasValue(" 0" );


< p style ="margin-bottom:.0001pt; line-height:normal; text-autospace:none">                
});


 


是的我确实关心我的ssdl部分是如何生成的,因为如果我的商店模型与我的数据库中的内容不匹配,那么隐式转换
将会发生,例如上面的内容会导致以下


db.Products.OfType< DiscontinuedProduct>()。ToArray();


select * from Discontinued ='1'


而不是 


select * from Discontinued = 1


因为在运行时ssdl部分是基于创建的csdl模型,一切都继续工作,但是如果在ssdl部分将列定义为nvarchar并且实际上它是varchar,则隐含的转换将发生
,没有人会注意到。我看到这种情况发生在你过滤一个查询,其属性在商店模型中定义为nvarchar,但在数据库中它被定义为varchar。我猜查询将定义nvarchar参数类型?


无论如何,在设计时我们可以尝试验证商店模型EF生成的商店模型是否与数据库生成匹配?




Zeeshan Hirani Apress的实体框架4.0食谱


http://weblogs.asp.net/zeeshanhirani

解决方案

Zeeshan,


 


我不相信目前可以设置鉴别器列的类型,但这是我们正在研究的内容并且会尝试(没有承诺!)
来启用此功能之前我们RTM。


 


对数据库验证商店模型是我们已经考虑过的事情,但它不太可能成为Code First的第一个版本。


 


谢谢,


< span style ="font-family:Calibri"> Arthur


is it possible in CTP5 to do TPH when your discriminator column is a bit field. If yes then how do i specify that. For instance the HasValue on the discriminator column takes in the storevalue but there is no way to specify the data type for that column.  in the example below Discontinued property has a store value of 1 or 0 but when i look at the edmx file which code first generates, it automatically makes the Discontinued column as string on the SSDL. how do i change that?

modelBuilder.Entity<Product>()

                .Map(mc =>

                {

                    mc.Requires("Discontinued").HasValue("1");

                })

                .Map<DiscontionuedProduct>(mc =>

                {

                    mc.Requires("Discontinued").HasValue("0");

                });

 

Yes i do care about how my ssdl section is generated because if my store model does not match what's in my database then implicit conversions are going to happen like for instance the above would result int the following

db.Products.OfType<DiscontinuedProduct>().ToArray();

select * from Products where Discontinued = '1'

instead of 

select * from Products where Discontinued = 1

Since at runtime the ssdl section is created based on the csdl model, everything continues to work and but if a column is defined at the ssdl section as nvarchar and actually it is varchar, implicit conversions will occur and nobody would ever notice. I see this happening when you filter a query with a property that is defined at the store model as nvarchar but in the database it is defined as varchar. I guess the query would then define nvarchar paramter type?

Is there anyway at the design time we can try to validate that the store model EF generates matches the store model if it was generated from the database?


Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani

解决方案

Zeeshan,

 

I don’t believe that it is currently possible to set the type of the discriminator column but this is something we are looking into and will try (no promises!) to enable this before we RTM.

 

Validation of the store model against the database is something we have done some thinking about, but it is unlikely to make it into the first release of Code First.

 

Thanks,

Arthur


这篇关于当鉴别器列有点时TPH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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