Tuesday, August 7, 2012

something like Dot Net LINQ in Java : JOOOQ

jOOQ : A peace treaty between SQL and Java

SQL was never meant to be abstracted. To be confined in the narrow boundaries of heavy mappers, hiding the beauty and simplicity of relational data. SQL was never meant to be object-oriented. SQL was never meant to be anything other than... SQL!

It's simple. With the jOOQ DSL, SQL looks almost as if it were natively supported by Java. For instance, get all books published in 2011, ordered by title

create.selectFrom(BOOK)
      .where(PUBLISHED_IN.equal(2011))
      .orderBy(TITLE)
 
jOOQ also supports more complex SQL statements. get all authors' first and last names, and the number of books they've written in German, if they have written more than five books in German in the last three years (from 2011), and sort those authors by last names limiting results to the second and third row, then lock first and last names columns for update
 
http://www.jooq.org/ 

How to add custom unbound property to LINQ2SQL , EF

We encountered this error because we did not map entity property OrganizationName to certain table column in the database. You can check the table mapping by right click the entity User and select “Table Mapping”.
However, I don’t think we can solve the problem by only adding a custom property in the designer. Even we add the Organization table in the Mapping Details and map the OrganizationName property to Organization.Name column, EF still wants us to map the PK of the Organization table to one property in the User entity. But the FK property of User entity is not Entity Key, so the entire mapping still fails. Hope I made it clear to understand.
To workaround, I would recommend you to write some hard code to add a custom property into the User class. Since all the entity classes are partial classes, we can create a new partial User class and add the custom property outside the EDM designer:
==========================================================================
public partial class User
{
public string OrganizationName
{
get
{
if (this.Organization != null)
return this.Organization.Name;
else
return string.Empty;
}
set
{
if (this.Organization != null)
this.Organization.Name = value;
}
}
}
==========================================================================
BTW, I should mention the lazy loading feature of EF4 which is not available in EFv1. That mentions the related entities will not be loaded until we try to access them. If this case, if we turn off the lazy loading feature by (context.ContextOptions.LazyLoadingEnabled = false), we need to add such a filter in the getter/setter of property OrganizationName:
==========================================================================
if (!this.OrganizationReference.IsLoaded)
{
this.OrganizationReference.Load();
}
==========================================================================

Monday, August 6, 2012

C# Open WPF window in WindowsForm APP

using System;  
using System.Windows.Forms;  
using System.Windows.Forms.Integration;  
 
var wpfwindow = new WPFWindow.Window1();  
ElementHost.EnableModelessKeyboardInterop(wpfwindow); 
wpfwindow.Show();
 
you need to add project reference to WindowsFormsIntegration.dll