本文介绍了AutoFixture EF实体约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

配置AutoFixture是否可以附加实体约束[从EDMX文件]?



例如。考虑我的EDMX文件的CSDL部分的代码片段:

 < EntityType Name =RndtAd> 
...
< Property Name =ADType =DecimalPrecision =12Scale =0Nullable =false/>
< Property Name =USERNAMEType =StringMaxLength =255FixedLength =falseUnicode =true/>
< Property Name =VERSIONType =DecimalPrecision =12Scale =4Nullable =false/>
< Property Name =EFFECTIVE_FROMType =DateTimePrecision =3/>
< Property Name =EFFECTIVE_FROM_TZType =DateTimePrecision =7/>
< Property Name =EFFECTIVE_TILLType =DateTimePrecision =3/>
< Property Name =EFFECTIVE_TILL_TZType =DateTimePrecision =7/>
< Property Name =IS_TEMPLATEType =StringMaxLength =1FixedLength =trueUnicode =false/>
< Property Name =IS_USERType =StringMaxLength =1FixedLength =trueUnicode =false/>
< Property Name =STRUCT_CREATEDType =StringMaxLength =1FixedLength =trueUnicode =false/>
< Property Name =AD_TPType =StringMaxLength =20FixedLength =falseUnicode =true/>
< Property Name =PERSONType =StringMaxLength =40FixedLength =falseUnicode =true/>
< Property Name =TITLEType =StringMaxLength =20FixedLength =falseUnicode =true/>
< Property Name =FUNCTION_NAMEType =StringMaxLength =20FixedLength =falseUnicode =true/>
< Property Name =COMPANYType =StringMaxLength =40FixedLength =falseUnicode =true/>
< Property Name =STREETType =StringMaxLength =40FixedLength =falseUnicode =true/>
...

如果 fixture.Create< ; RndtAd>()随机生成所有先前约束的实体。



我有什么选择?所有的建议都是欢迎的。



编辑 我不限于AutoFixture。如果还有另外一个工具,我也可以这样做。

解决方案

AutoFixture没有内置的支持对于实体框架,但在过去几年中,有几个人已经打了自己的战斗来整合两者。



这是Google搜索引起的一个问题: / p>









也许您可以通过查看其中一些资源找到一些灵感。


Is it possbile to configure AutoFixture so that it adheres the entity constraints [from the EDMX file]?

E.g. Consider a snippet from the CSDL section of my EDMX file:

<EntityType Name="RndtAd">
...
<Property Name="AD" Type="Decimal" Precision="12" Scale="0" Nullable="false" />
<Property Name="USERNAME" Type="String" MaxLength="255" FixedLength="false" Unicode="true" />
<Property Name="VERSION" Type="Decimal" Precision="12" Scale="4" Nullable="false" />
<Property Name="EFFECTIVE_FROM" Type="DateTime" Precision="3" />
<Property Name="EFFECTIVE_FROM_TZ" Type="DateTime" Precision="7" />
<Property Name="EFFECTIVE_TILL" Type="DateTime" Precision="3" />
<Property Name="EFFECTIVE_TILL_TZ" Type="DateTime" Precision="7" />
<Property Name="IS_TEMPLATE" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="IS_USER" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="STRUCT_CREATED" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="AD_TP" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="PERSON" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="TITLE" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="FUNCTION_NAME" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="COMPANY" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="STREET" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
...

What I would like if fixture.Create<RndtAd>() generated randomly an entity where all the previous constraints are satisfied.

What options do I have? All suggestions are welcome.

EDIT. I'm not bound to AutoFixture. If there is another tool which does the job, I'm ok with that too.

解决方案

AutoFixture has no built-in support for Entity Framework, but during the last couple of years, several people have fought their own battles to integrate the two.

Here's what a Google search turned up for me:

Perhaps you can find some inspiration by looking some of those resources over.

这篇关于AutoFixture EF实体约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:48