Closed SteveRuble closed 8 years ago
Thank you very much. But the unit tests fail?
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?
Updated nuget package, and added your name to the package description.
@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...
@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.
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 eachFunctionType
to clarify what is required for each type of function. This resolves #1, although it may not be the best resolution.