extension-methods

Missing QueryableExtensions in EF 6

泄露秘密 提交于 2019-12-23 11:22:30
问题 I can't call the new QueryableExtensions ( ToListAsync , ForEachAsync ,...) provided with EntityFramework 6. But i can call others ( Include , Intersect ). I've a reference to System.Data.Entity . So apparently, i've an older version of System.Data.Entity , with the latest version of EntityFramework. Is it possible? My code does not compile and I cannot see the ForEachAsync method in the object browser. I'm working with Visual Studio 2013, .Net 4.5, EntityFramework 6.1.3, Wpf. Edit Entity

Missing QueryableExtensions in EF 6

人走茶凉 提交于 2019-12-23 11:22:20
问题 I can't call the new QueryableExtensions ( ToListAsync , ForEachAsync ,...) provided with EntityFramework 6. But i can call others ( Include , Intersect ). I've a reference to System.Data.Entity . So apparently, i've an older version of System.Data.Entity , with the latest version of EntityFramework. Is it possible? My code does not compile and I cannot see the ForEachAsync method in the object browser. I'm working with Visual Studio 2013, .Net 4.5, EntityFramework 6.1.3, Wpf. Edit Entity

Is an Extension Method the only way to add a function to an Enum?

放肆的年华 提交于 2019-12-23 08:51:08
问题 I have a Direction Enum: Public Enum Direction Left Right Top Bottom End Enum And Sometimes I need to get the inverse, so it seems nice to write: SomeDirection.Inverse() But I can't put a method on an enum! However, I can add an Extension Method (VS2008+) to it. In VB, Extension Methods must be inside Modules. I really don't like modules that much, and I'm trying to write a (moderately) simple class that I can share in a single file to be plugged into other projects. Modules can only reside

Html Helper Extensions not being found

大兔子大兔子 提交于 2019-12-23 08:43:06
问题 I'm using the release version of ASP.net MVC and I seem to be getting this error a lot 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' and no extension method 'RenderPartial' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) which is very odd since I can browse to System.Web.Mvc.HtmlHelper and all the extension methods are there. Even stranger is that I can compile and all

How can I define an extension member on an F# unit of measure?

别等时光非礼了梦想. 提交于 2019-12-23 07:35:28
问题 Leaving aside whether we should use units of measure for unitless concepts like angles, suppose I have define degree and radian units in F# type [<Measure>] degree = static member ToRadians (d:float<degree>) : float<radian> = d * (Math.PI * 1.<radian>) / 180.0<degree> and [<Measure>] radian = static member ToDegrees (r:float<radian>) : float<degree> = r * 180.0<degree> / (Math.PI * 1.<radian>) I can use them relatively easily like 4.0<degree> |> degree.ToRadians It seems like extension

Explicitly use extension method

删除回忆录丶 提交于 2019-12-23 07:09:03
问题 I'm having a List<T> and want get the values back in reverse order. What I don't want is to reverse the list itself. This seems like no problem at all since there's a Reverse() extension method for IEnumerable<T> which does exactly what I want. My problem is, that there's also a Reverse() method for List<T> which reverses the list itself and returns void. I know there are plenty of ways to traverse the list in reverse order but my question is: How do I tell the compiler that I want to use the

Nice, clean cross join in Linq using only extension methods [duplicate]

旧时模样 提交于 2019-12-23 06:56:05
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Nested “from” LINQ query expressed with extension methods I'm sure this has been asked before, but I honestly couldn't find anything. I'm curious what the equivalent syntax would be for the following using only built-in Linq extension methods: var z1 = from x in xs from y in ys select new { x, y }; I can get the same results with this: var z2 = xs.SelectMany(x => ys.Select(y => new { x, y })); But it produces

Can't Translate Extension Method Into Store Expression

喜你入骨 提交于 2019-12-23 05:13:36
问题 I have an extension method as follows: public static bool SatisfiesSomeCondition(this Post post, SomeObj someObj) { return post.SomeObjId == someObj.SomeObjId; } And i'm trying to use it like this: var query = ctx.Posts.Where(p => p.SatisfiesSomeCondition(someObj)).ToList(); But i get the error: LINQ to Entities does not recognize the method 'Boolean SatisfiesSomeCondition(xx.xx.xx.Post, xx.xx.xx.SomeObj)' method, and this method cannot be translated into a store expression. If i change the

Get name from variable in calling method - creating calling method signature, parameters and values

不羁岁月 提交于 2019-12-23 04:57:14
问题 I'm looking for a way to get hold of the name of a variable that was passed into an extensionmethod. I want to have the name of the parameter in the calling variable. Sounds strange, let me explain. assume this piece of testing code private static void TestingMethod(string firstParam, int secondParam, bool thirdParam) { try { throw new InvalidOperationException("This named optional params stuff, it's just not working boss"); } catch (Exception ex) { GenericLog_Exception(ex, "it's on fire,

RazorEngine extension method fails with RuntimeBinderException after upgrade to Razor 2/ RE 3.2

牧云@^-^@ 提交于 2019-12-22 21:42:44
问题 I have a RazorEngine project that fails following an upgrade to Razor 2.0 and RazorEngine 3.2.0 This worked fine in the previous Razor 1.0 based version of RazorEngine (3.0.8). I have an instance ( myInstance ) of a class ( MyClass ) and and extension method: namespace MyCompany.Extensions { public static class MyClassExtensions { public static string ExtensionMethod(this MyClass thing) { // do stuff } } } I want to call this in a RazorEngine view (simplified example, there are loads of these