Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 使用EF电动工具-检索十进制精度和刻度_Entity Framework_T4 - Fatal编程技术网

Entity framework 使用EF电动工具-检索十进制精度和刻度

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

我需要设置十进制字段的精度和比例值

使用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 = 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 #>;