(LINQ) Discover the SQL Code generated by the Entity Framework
Use the following:
IQueryable<ReturnType> LinqQuery=(YOUR LINQ GOES HERE);
var SqlToExecute = ((System.Data.Objects.ObjectQuery)LinqQuery).ToTraceString();
(WPF) StaticResource vs DynamicResource
Static resources are resolved at compile time, whereas dynamic resources are resolved at runtime.
- Use DynamicResources when the value of the resource could change during the lifetime of the Application.
- Use StaticResources when it’s clear that you don’t need your resource re-evaluated when fetching it.
Static resources perform better than dynamic resources.
(NHibernate) Detached objects in NHibernate
You have a business object that you have loaded from the database during an ISession. The session has been closed and now if you try to access some of the properties of the BO that are lazy loaded you will get an exception. A way to reattach this BO to an ISession is by using the following:
- Use ISession.Lock() if you are sure that the BO has not been changed
- Use the ISession.Update() if the BO has been changed
(Transact SQL) How to delete duplicate rows from a table
Suppose that you have the table TestTable in the database with duplicates in the column DuplicatesColumn.
Write the following:
ALTER TABLE TestTable ADD RowInc INT IDENTITY(1,1)
DELETE FROM TestTable WHERE RowInc NOT IN (SELECT MIN(RowInc) FROM TestTable GROUP BY DuplicatesColumn)
ALTER TABLE TestTable DROP COLUMN RowInc
(Transact SQL) Copy a table from one DB to another
SELECT * INTO DatabaseTarget.dbo.TableToCopy FROM DatabaseSource.sbo.TableToCopy
(WPF) StringFormat in bindings
Follow the link to Lester's WPF Blog.
(Reporting) Reading an .rdlc file which is in an Assembly.
If you set your report file (.rdlc) as embedded resource, the file will be compiled within the assembly. Suppose you have the report named TestReport.rdlc which is in a project named TestProject. Then in order to read this report in your reportViewer control (this.ReportViewer) you need the following code:
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom("TestProject.dll");
System.IO.Stream stream = assembly.GetManifestResourceStream("TestProject.TestReport.rdlc");
this.ReportViewer.LocalReport.LoadReportDefinition(stream);