Showing posts with label poco. Show all posts
Showing posts with label poco. Show all posts

Monday, April 8, 2013

[.NET] Adding POCO Entities in the WCF mix

When you want to separate the domain model such that it is now housed a separate project for other layers/projects to use, you must remove proxy creation and assign the domain object and properties with DataContracts and DataMember attributes.

To remove proxy creation, simply put in the service implementation constructor

DBcontext.ContextOptions.ProxyCreationEnabled = false

Tuesday, December 4, 2012

[.NET] I don't have time for this. POCO Generator, Function Imports, Returning None

1. Used POCO Generator to create Function Imports
2. Had a Function that returns none
3. POCO Generator does not generate Functions that return none.

WUDDDAAAPPPAAAACCCKKERRRR

Alright, this was such a headache, but thanks to Matt Johnson in this stack overflow link:
http://stackoverflow.com/questions/3797248/update-function-import-not-displaying-in-context-file

...problem was solved.

Here is the Function Import region of the .tt file:


region.Begin("Function Imports");

        foreach (EdmFunction edmFunction in container.FunctionImports)
        {
            var parameters = FunctionImportParameter.Create(edmFunction.Parameters, code, ef);
            string paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
            string returnTypeElement = edmFunction.ReturnParameter == null
? null : code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));

#>
    <#=Accessibility.ForMethod(edmFunction)#> <#= returnTypeElement == null ? "int" : ("ObjectResult<" + returnTypeElement + ">") #>  <#=code.Escape(edmFunction)#>(<#=paramList#>)
    {
<#
            foreach (var parameter in parameters)
            {
                if (!parameter.NeedsLocalVariable)
                {
                    continue;
                }
#>

        ObjectParameter <#=parameter.LocalVariableName#>;

        if (<#=parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"#>)
        {
            <#=parameter.LocalVariableName#> = new ObjectParameter("<#=parameter.EsqlParameterName#>", <#=parameter.FunctionParameterName#>);
        }
        else
        {
            <#=parameter.LocalVariableName#> = new ObjectParameter("<#=parameter.EsqlParameterName#>", typeof(<#=parameter.RawClrTypeName#>));
        }
<#
            }
#>
        return base.ExecuteFunction<#= returnTypeElement == null ? "" : ("<" + returnTypeElement + ">")#>("<#=edmFunction.Name#>"<#=code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))#>);
    }
<#
        }

        region.End();