Entity framework 使用EF电动工具-检索十进制精度和刻度
我需要设置十进制字段的精度和比例值 使用EF Powertools模板,我想在Mapping.tt中自定义此部分:Entity framework 使用EF电动工具-检索十进制精度和刻度,entity-framework,t4,Entity Framework,T4,我需要设置十进制字段的精度和比例值 使用EF Powertools模板,我想在Mapping.tt中自定义此部分: foreach (var prop in efHost.EntityType.Properties) { var type = (PrimitiveType)prop.TypeUsage.EdmType; var isKey = efHost.EntityType.KeyMembers.Contains(prop); var storeProp = efHo
foreach (var prop in efHost.EntityType.Properties)
{
var type = (PrimitiveType)prop.TypeUsage.EdmType;
var isKey = efHost.EntityType.KeyMembers.Contains(prop);
var storeProp = efHost.PropertyToColumnMappings[prop];
var sgpFacet = storeProp.TypeUsage.Facets.SingleOrDefault(f => f.Name == "StoreGeneratedPattern");
var storeGeneratedPattern = sgpFacet == null
? StoreGeneratedPattern.None
: (StoreGeneratedPattern)sgpFacet.Value;
// Other code from Mapping.tt
if (type.ClrEquivalentType == typeof(decimal))
{
int precision = **[Retrieve Precision Value]**;
int scale = **[Retrieve Scale Value]**;
configLines.Add(String.Format(".HasPrecision({0}, {1})", precision, scale));
}
}
我如何检索每个的精度和比例值
谢谢
史蒂夫你可以按如下方式做
if (edmType.ClrEquivalentType == typeof(decimal))
{
Facet precisionFacet= property.TypeUsage.Facets.SingleOrDefault(f => f.Name == "Precision");
Facet scaleFacet = property.TypeUsage.Facets.SingleOrDefault(f => f.Name == "Scale");
hasPrecision=String.Format(".HasPrecision({0}, {1})", precisionFacet.Value, scaleFacet.Value);
}
if(!entityPropertyToColumnMapping.Item2.Keys.Contains(property)) continue;
string hasColumnName = string.Format(".HasColumnName(\"{0}\")", entityPropertyToColumnMapping.Item2[property].Name);
if(property.Name=="AccountID"){blnHasAccountId=true;}
>
this.Property(t=>t.);
你能编辑你的答案吗?因为在格式上有明显的错误。
this.Property(t => t.<#= property.Name#>)<#=hasColumnName+ hasPrecision + generateOption + required + unicCode + fixedLength + maxLength #>;