Dixin / EntityFramework.Functions

EntityFramework.Functions library implements Entity Framework code first support for stored procedures (with single result type, multiple result types, output parameter), table-valued functions (returning entity type, complex type), scalar-valued functions (composable, non-composable), aggregate functions, built-in functions, niladic functions, and model defined functions.
https://weblogs.asp.net/Dixin/EntityFramework.Functions
MIT License
79 stars 27 forks source link

Updated API to support composing Table Valued Functions #2

Closed SteveRuble closed 8 years ago

SteveRuble commented 8 years ago

Modified FunctionAttribute to optionally accept namespaceName parameter which must be set for composed calls to Table Valued Functions to work. Added attributes derived from FunctionAttribute which take the necessary parameters for each FunctionType to clarify what is required for each type of function. This resolves #1, although it may not be the best resolution.

Dixin commented 8 years ago

Thank you very much. But the unit tests fail?

image

SteveRuble commented 8 years ago

My initial commit was broken, but I fixed it in commit 54c4ae9. I thought that subsequent commits I made to the same branch in my fork would be included in the pull request, but maybe I misunderstood. Should I do another pull request?

Dixin commented 8 years ago

Updated nuget package, and added your name to the package description.

skurik commented 2 years ago

@SteveRuble I think this PR makes it impossible to use built-in TVFs (like STRING_SPLIT) with code-first.

I have

[ComplexType]
public class StringSplitValue
{
    public string Value { get; set; }
}

public abstract class DbContext : System.Data.Entity.DbContext
{
    [TableValuedFunction(name: nameof(String_Split), dbContextName: "CodeFirstDatabaseSchema")]
    public IQueryable<StringSplitValue> String_Split(string @string, string separator)
    {
        var sourceParameter = new ObjectParameter("Source", @string);
        var separatorParameter = new ObjectParameter("Separator", separator);

        return ObjectContext.CreateQuery<StringSplitValue>($"STRING_SPLIT(@Source, @Separator)", sourceParameter, separatorParameter);
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Conventions.Add(new FunctionConvention<DbContext>());
        modelBuilder.AddComplexTypesFromAssembly(typeof(DbContext).Assembly);
    }
}

and the FunctionAttribute constructor is throwing

The namespaceName parameter must be set for Table Valued Functions.

But I can't use anything else than CodeFirstDatabaseSchema, it's the hard-coded namespace value for code-first...

SteveRuble commented 2 years ago

@skurik You could be right, but I am not going to be able to help you with this, sorry. I haven't even used EF since 2018.