Dynamic resultset with dapper on 3.5 - c#-3.0

I've got a store procedure call returning a recordset whith field unknown in advance. For some interop reason I need to make it working on 3.5, so I don't have any dynamic support.
Is there some built-in solution in dapper? I did not find any by myself.
If there is no such a solution, does it make sense ( and does it work ) to create on the fly a type exposing the property I would fetch ?
EDIT
I managed to add a completely external solution ( without tweaking the original codebase ) by creating a dynamic object in c# 3.0.
Here is the extension dapper code
and here the factory for the dynamic object.

Well, actually the dynamic support in dapper is implemented via ExpandoObject, which is basically just a dictionary. It would be pretty simple to tweak the existing code to return IDictionary<string,object> instead of dynamic in the case of 3.5

Related

Globally Tag EF Core Queries with ".TagWithCallSite()"

With the release of the .TagWithCallSite() method in EF Core 6.0 I was wondering if there is a way to apply this globally on every query run via a DbContext in some way?
It would be much better to apply this across the whole project without having to put it on each query individually.
TagWithCallSite accepts parameters marked with CallerFilePathAttribute and CallerLineNumberAttribute which are filled in by compiler (or manually if needed) during build so it is impossible to set up globally.
No, you cant't do that.
When you explicitly define TagWithCallSite(), complier automatically fills default parameters filePath and lineNumber. It is not possible to define that for all queries because compiler do not store such information in Expression Tree.

Can SqlFunctions work with Dynamic Linq?

Is it possible to get SqlFunctions to work with Dynamic Linq? I noticed this post from the SO site which seems to suggest that it is possible, however, every time I run this query below in a .NET project (not .NET Core):
query.Where("SqlFunctions.StringConvert((double?)Property).Contains(\"x\")");
It spits back a message that:
No property or field 'SqlFunctions' exists in type 'Entity'
Worked for me. Check you have created your own custom DLinq with added SqlFunctions type to predefinedTypes as per the post.
Personally I'm adding SqlFunctions dynamically to my DLinq. See https://stackoverflow.com/a/18313782/525788 for guidance.

Entity Framework Code First use SQL Server datetime2 instead of datetime everywhere

I know this can be accomplished using the Fluent API on a single property, but I want to have this automatically happen for everywhere I use a .NET DateTime in my model. Here's an example of doing a single property:
modelBuilder.Entity<T>()
.Property(f => f.MyDateTimeProperty)
.HasColumnType("datetime2");
But instead of only on this one property I want it to happen everywhere automatically. There is a fix for this in Model First by editing the T4 generation template so I know it can be done there but I need the same thing in Code First.
You want to use a Custom Code First Convention.
There's an example of exactly what you are trying to do here: http://msdn.microsoft.com/en-us/data/jj819164.aspx

What is the difference between Entity.GetAttributeValue<T>(name) and Entity[name] in Dynamics CRM?

When coding against the CRM SDK using late binding what is the difference between accessing attributes using the GetAttributeValue method and accessing the attributes directly on the Entity object?
I am still very new to .NET and c# so if it is a simple language/platform understanding issue then apologies but maybe that's why I can't find much on the difference.
entity["myattributename"] will throw an exception if you attempt to access an attribute that is not in the attribute collection of the entity. It will also return it as an object.
entity.GetAttributeValue<T> will return the default value of the type if not found, and will not throw an exception if it isn't in the attributes collection of the entity.
The entity.GetAttributeValue<T> will return an IEnumerable object which can be used in LINQ expressions. This may greatly speed-up development time and reduce lines of code logic. Based on Daryl's response (good explaination here: ).

WCF Data Service with EF fails to expose imported functions

(I am also using .NET 4.0 and VS 2010.)
I created a function import returning a complex type, as explained at http://msdn.microsoft.com/en-us/library/bb896231.aspx. The function import and new complex type appear in my .edmx file and in the Designer.cs file. However, the function does not appear when I view the service in the browser, and when I add or update a service reference in the client project, the function does not appear there either - as is to be expected, given the first result.
Creating an imported function and using it seems conceptually very simple and straightforward, and one would think it would just work, as Microsoft's step-by-step instructions appear to suggest: http://msdn.microsoft.com/en-us/library/cc716672.aspx#Y798 (which article shows the SP returning entity types - I tried this also, and it doesn't work for me either).
This blog post shows the addition of a method to the DataService class, which Microsoft's instructions omit: http://www.codegain.com/articles/wcf/miscellaneous/how-to-use-stored-procedure-in-wcf-data-service.aspx I tried adding one method returning a list of entity types and another returning a list of complex types, and still had no success. I still could not access the functions, either directly via the browser or from the client application via a service reference.
Thanks in advance for any help with this.
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
MS would do well to add a note to the walkthroughs stating that the above bit of code must be there. (It may be better to enable each operation explicitly than to use "*".)
http://www.codegain.com/articles/wcf/miscellaneous/how-to-use-stored-procedure-in-wcf-data-service.aspx shows that line of code. Also, something it is there in the code, commented out, when one creates the WCF Data Service. Some of us like to delete commented-out code that we aren't using and that seems irrelevant - perhaps doing so a bit prematurely, sometimes.