0

I am Getting below error in Framework 4.5 WCF application.

enter image description here

Is there any missing file or else. I don't getting exactly here.

Abhishek B.
  • 5,112
  • 14
  • 51
  • 90

2 Answers2

0

Depends how your class does look like. Based on your screenshot you should change it to this

public void Update<T>(T obj, params Expression<Func<T, object>>[] propertiesToUpdate)
{
}

Your version is only working, if the class would look like

public class YourClass<T>
{
   public void Update(T obj, ...
   {
   }
}

And here are the basics.

Edit

Either you forgot to post it or you're doing it wrong.

If you're looking at the doc of DbContext.Set<T>(), then you'll see, that there is a constrain saying where T : class. (That's what I already mentioned in a comment.) That means, that your generic type has to meet the same requirement. Therefore you need to change your method to the following, since it need to be at least as specific as DbContext.Set<T>().

public void Update<T>(T obj, params Expression<Func<T, object>>[] propertiesToUpdate) where T : class
{
}

Last but not least, an advice. Deal with the basic of generics. It's pretty important. Once you have understood the whole thing, it can be very powerful in certain scenarios.

DHN
  • 4,807
  • 3
  • 31
  • 45
  • I have created method in class.. I have updated but Context.Set() is not working.. can I share teamviewer to you. – Abhishek B. Apr 21 '16 at 08:04
  • @AbhishekBhalani: Well since I don't know how `Context.Set()` is definied, it's difficult to help. Might be that there is a constrain defined, which is not compatible with the other `T`. Have a look [here](https://msdn.microsoft.com/en-us/library/d5x73970.aspx). – DHN Apr 21 '16 at 08:11
  • 1
    @AbhishekBhalani: How about sharing the code of `Update`. The tooltip on the picture is hidding some details. If possible, share also the code of `Context.Set`. – DHN Apr 21 '16 at 08:14
  • http://stackoverflow.com/questions/15336248/entity-framework-5-updating-a-record I was trying same. – Abhishek B. Apr 21 '16 at 11:49
  • I can show you via teamviewer if you have sometime. – Abhishek B. Apr 21 '16 at 11:55
  • I want to update entity model. but you know sometime it throw datetime error. It throws "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated." – Abhishek B. Apr 21 '16 at 12:00
0

You need to do like this:

public void Update<T>(Task obj, params Expression<Func<T, object>>[] propertiesToUpdate)
DevJoe
  • 419
  • 3
  • 17