0

I am maintaining a visual studio 2008 application (website project). There is no chance to upgrade to higher version of.net framework or upper version of entity framework. Like many IT shops, unless there are major issues, people are not going to allow me to do major upgrade on the system.

The .net framework is 3.5. and the EF version is 1.0

I need to change my program, so my select linq statement will work

Calling a SQL User-defined function in a LINQ query

As you can tell, I need to include stored function as a part of select statement

So I copied the statement.

I have struggled for hours, and I keep getting compilation.

//..various using statement
using System.Data.Objects.DataClasses;
using System.Data.Metadata.Edm;

//..other class
public static class EntityFunctions 
{
    [EdmFunction("FBLModel.Store", "SampleFunction")]
    public static int SampleFunction(int param)
    {
        throw new NotSupportedException("Direct calls are not supported.");
    }
}

I keep getting compilation errors

error CS0246: The type or namespace name 'EdmFunctionAttribute' could not be found (are you missing a using directive or an assembly reference?)

I have searched the whole internet include stackoverflow and MSDN blog, the namespace looks correct

enter image description here

Any suggestions? Thank you

6
  • You're exception indicates that nothing should directly call the method. This makes me suspect no methods directly call the method or possibly even the whole library and so the compiler doesn't include the reference when it builds to solution since it thinks it's "optimizing" output by ignoring the unused reference. Can you try creating a hard reference so you know for certain that the compiler isn't ignoring it? e.g. Create a public property called test, then get the value in your main project once, just so the code touches it at least once and ensure the assembly is loaded? Commented Jul 15, 2017 at 6:41
  • above i say the compiler ignores it, but that's not accurate since the dll will still be included in the output. It's more of a runtime optomization that I'm talking about where the assembly is never loaded. Just wanted to clarify that :) Commented Jul 15, 2017 at 6:47
  • It could be a problem with the T4 templates. Perhaps they belong to the wrong EF version? Go to Model.Context.tt and check that the using System.Data.Objects.DataClasses; is included. I got the hint from this post. Commented Jul 16, 2017 at 16:36
  • It's a typical trap to think that solving issues time and again is cheaper than upgrading. It's a logical flaw (just read a bit in Thinking, Fast and Slow, Kahneman). Besides, EF 1 is notoriously immature, it's hardly used anymore, so you're virtually on your own. Also, it's an illusion to think that you're going to upgrade when there are major issues. The best time to upgrade (and regression test) is when there are NO issues. Commented Jul 16, 2017 at 22:17
  • Thanks for everyone's response. It does not context.tt. Strange. It has dbml. I can no longer using gui. I have to go to file to change manually. This is the second in my career I have to do it. I inherit. There is not much I can do. I have 4 projects to do. For this old project, I just have to make sure it does not break. Eventually, it will upgrade. Right, it is not a right time BC I got no time. Oh, this is website project. I need to figure how it is reference dll. I really want to K... the original developer. I did 2008 b4. It was not like this! Commented Jul 17, 2017 at 14:31

1 Answer 1

0

The problem here is that you have a conflicting reference with your namespaces.

The System.Data.Metadata.Edm namespace contains a class called EdmFunction. The System.Data.Objects.DataClasses namespace contains a class called EdmFunctionattribute (which is the one you are trying to use).

For some reason your code is referencing the EdmFunction class. Try removing the namespace import for System.Data.Metadata.Edm, as you probably didn't want to import this in the first place.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.