Can we convert ISingleResult<T> to IList<T> - linq-to-sql

I started using LINQ to SQL recently. On my DMBL designer, I open the server explorer and drag a stored proc onto the designer.
I open the properties for the Method in the designer and see that its return type is AutoGenerated. I look at the designer.cs class and it says
the return type is ISingleResult<GetEmloyeeeRecordDataResult>.
Can this be cast to IList<GetEmployeeRecordDataResult>?
I tried doing this and there are no compile time errors. I am trying to understand what a ISingleResult<T> is and how it can be cast to IList<T>.

Use ToList()

Related

Working DLL code fails with Run-time error 13: Type mismatch when debugging

This question is a stumper, for experts only.
We are using Visual Studio 6 to develop a complex COM Add-In for Access. When compiled, the Add-In works fine. But, when we use Ctrl-F5 to put the VB6 IDE in debug mode, Access throws a
Run-time error 13: Type mismatch
error when it tries to assign the Access Application.COMAddIns("AddInName").Object reference to an early-bound VBA variable of a type exposed in the AddInName type library.
Further information:
The Access application uses objects created by calls to the Add-In
The Add-In DLL also serves as a type library that is included in Access VBA References
The type Access requests from the Add-In is defined in the AddInName type library
In Access VBA, the failing code looks like this:
Public Function GetAddInRef As AddInName.SomeClass
Dim objSomeClass As AddInName.SomeClass
' .Object is set to a SomeClass instance in IDTExtensibility2_OnConnection
Set objSomeClass = Application.COMAddIns("AddInName").Object ' => Error 13!
Set GetAddInRef = objSomeClass
End Function
If you change the type of objSomeClass to Object, the assignment works. If you set a break on the offending line, you can do things like this in the Immediate window:
? TypeName(objSomeClass)
AddInName.SomeClass
? TypeOf objSomeClass Is AddInName.SomeClass
False
So it is saying that the class name of objSomeClass is "AddInName.SomeClass", but it is not of type AddInName.SomeClass. Madness!
Further, if you put in code that exposes the CLSID for the Access-side reference and the Add-In originated object, they both return the same GUID! So why does VBA complain that the types are different?
Does anyone have any insight into what is happening here? I would be very grateful for any help.
I'm guessing (I am no expert) it's because AddInName.SomeClass is not an object, it is of type AddinName.SomeClass. Drop the .Object off of Application.COMAddIns("AddInName").Object and I think it will work just fine. If you need it as an object for somewhere else in your code, then change your AddInName.SomeClass types to Object and leave the .Object on Application.COMAddIns("AddInName").Object and it should work.
So a colleague of mine stumbled upon the answer: Set Access and VB6 permissions to administrator! I tried it, and Voilà, debugging works.
For each of the following executable files, Right-click, Properties, Configuration, then check Run this program as an administrator:
Office path:
MSACCESS.EXE (or EXCEL.EXE or WINWORD.EXE ...)
C:\Program Files (x86)\Microsoft Visual Studio\VB98\
VB6.EXE
LINK.EXE
Notes:
It probably helps to develop VB6 apps using an administrative login, too.
This makes sense, because VB6 had its start in the Windows 95 era, when users were pretty much the king of their OS instance.
Caveat: this may not be a perfect solution for very complex Access forms with lots of DLL interaction, but it is much better than nothing!

Using Delphi component under C++ Builder makes calls to a wrong function

I'm trying to use Graphics32 package. Graphics32 was compiled and installed without any issue.
When I try to execute (debug) following code under C++ Builder XE3
TBitmap32* bmp = new TBitmap32();
bmp->LoadFromFile("d:\\sample.bmp");//This calls SaveToStream instead of LoadFromFile
...
it calls another member function SaveToStream which I can trace into and step while debugging until AV rises.
I have never encountered such behavior before.
Is there any compiler directive I'm missing or some workaround to make proper function call?
Update: I use the Graphics32 source from SVN. Everything works good if I use code prior to revision 2122.

what is the VBA for the USING statement

In csharp or vb.net we use the using statement for reasons that we know: One can open the database and close it automatically without writing it explicitly.
I would like to do the samething in VBA
how to do it?
Are all VB.NET statement/keywords/ available in VBA ?
how to tell if a given statement is(was) known in VBA ? Is it there a library(glosary) of all VBA statements/keyword/operators ?
c#
using(var db=new MyDbContext()){
//do work here
}
vb.net
Using s = New MyDbContext()
'--..do work here
End Using
Answering just your first question, as you've hinted, Using is just syntactic sugar for calling Dispose() on an object instance which implements the IDisposable interface.
It is equivalent to
Dim s as MyDbContext
Try
s = New MyDbContext()
// ...
Finally
s.Dispose()
End Try
Since VBA doesn't support the Using sugar, and in the absence of structured Try..Catch exception handling, you'll need to explicitly call Dispose() on all paths which control the lifespan of the object (MyDbContext in your case). In which case you may as well have just used .Close()
There is no VBA equivalent to the Using statement.
The VBA developer documentation provides samples and even downloadable offline versions of the VBA documentation.

System.TypeInitializationException between two program in F#

I'm working on a project and I become always an Exception "TypeInitializationException".
I tried to give a string to a global string variable but it failed.
That's the code for the viewmodel and it failed on the second line
| {State = _}, ConsumablesClicked vm ->
Testtyp <- vm.TrackPosition.ToString()
That's on the other program
let mutable Testtyp = ""
I become this InnerException "Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.".
"The type initializer for '.$BarcodeGenerieren' threw an exception.", that's the exception explication.
Has someone a Idea how solve this?
That exception indicates that some code is trying to call Console.ReadKey when the standard input for that process has been redirected (see e.g. Allowing redirection of StandardInput of a C# application when doing "Console.ReadKey"). The solution is not to call Console.ReadKey, but it's not clear from your description where this is actually happening (perhaps in the static constructor for one of your types?).
I found the solution after a lot of try and it was only, that I had a Console.Readkey in my code, that I forgot to delete.
I had before a console apllication and I transformed it to be a class.

Reporting Services custom assembly: accessing report parameters

I'm writting a custom assembly to be referenced in a report. I'd like to be able to access the Report object from that assembly, so that I could then access the report parameters and other stuff that I can access in custom RDL code by using Report.stuff.
I obviously need to reference some reporting services assembly to do this, yet I can't figure out which. I tried Microsoft.ReportingServices.ProcessingCore, since it has a class Report with various properties like Parameters etc., but when I tried to pass the Report object from the RDL custom code section to my class, I got this error:
Unable to cast object of type 'ReportExprHostImpl' to type 'Microsoft.ReportingServices.ReportRendering.Report'.
There's also an assembly which exposes various interfaces and an abstract class Report, but it doesn't seem to have the parameters as a property.
So the question is, how could I achieve this, what assembly do I have to reference ? And if possible, can I access the Report object without passing it from the RDL, i.e. so that I could just register an instance of my class and later write expressions like:
=Utils.DoStuffWhileReferencingReportParameters(Fields!field.Value)
Reference these two dlls in your library:
Microsoft.ReportingServices.ProcessingCore
Microsoft.ReportingServices.ProcessingObjectModel
Put the following code in your library (as an example)
using Microsoft.ReportingServices.ReportProcessing.ReportObjectModel;
public static string Test(Parameters item)
{
return item ["my_parameter_name"].Value.ToString();
}
Here’s an example expression to use in your RDL file:
=MyNameSpace.MyStaticClass.Test(Parameters)