Hello Ricardo,

Thanks for the patch. I'll take a deeper into it and see what I can do. Is
there any other scenario where LINQ query is not working using Jet driver?

Hadi

On Sat, May 29, 2010 at 7:30 AM, Ricardo <[email protected]> wrote:

> I am trying to use Jetdriver and new version of Linq, but it is not
> working. I made a test below using the Foo class of Jetdriver unit
> tests to make some queries with strings. I think LINQ driver of has
> some problems and is not finished, but I think these queries work with
> SQL Server driver.
>
> The new LINQ create some SQL queries like the examples below that do
> not work with Access.
>
> LINQ
> s.Query<Foo>().Where(f => f.Module == "bar");
>
> SQL
> NHibernate: select foo0_.ModuleId as ModuleId4_, foo0_.`Module` as
> Module2_4_, foo0_.ModuleValue as ModuleVa3_4_, foo0_.ShortName as
> ShortName4_, foo0_.LongName as LongName4_, foo0_.Description as
> Descript6_4_ from Foo foo0_ where (foo0_.`Module` is null) and (? is
> null) or foo0_.`Module`=?;@p0 = 'bar' [Type: String (3)]
>
> LINQ
> var q = s.Query<Foo>().Where(f => f.Module.Contains("a"));
>
> SQL
> NHibernate: select foo0_.ModuleId as ModuleId4_, foo0_.`Module` as
> Module2_4_, foo0_.ModuleValue as ModuleVa3_4_, foo0_.ShortName as
> ShortName4_, foo0_.LongName as LongName4_, foo0_.Description as
> Descript6_4_ from Foo foo0_ where foo0_.`Module` like
> ('%'||?||'%');@p0 = 'a' [Type: String (1)]
>
>
> I made some workarounds , force true to UseNamedPrefixInSql to use
> named parameters instead of "?" in the JetDriver class and register
> some functions in  JetDialect class
>
>  RegisterFunction("concat", new
> VarArgsSQLFunction(NHibernateUtil.String, "(", "+", ")"));
>           RegisterFunction("length", new StandardSQLFunction("len",
> NHibernateUtil.Int32));
>           RegisterFunction("substring", new
> SQLFunctionTemplate(NHibernateUtil.String, "mid(?1, ?2+1, ?3)"));
>           RegisterFunction("locate", new
> SQLFunctionTemplate(NHibernateUtil.Int32, "(instr(?3+1,?2,?1)-1)"));
>
>
>
>  [Test]
>        public void can_execute_string_functions()
>        {
>            object savedId;
>            using (var s = SessionFactory.OpenSession())
>            {
>                using (var t = s.BeginTransaction())
>                {
>                    savedId = s.Save(new Foo
>                                         {
>                                             ModuleId = -1,
>                                             Module = "bar"
>                                         });
>
>                    t.Commit();
>                }
>
>                using (var t = s.BeginTransaction())
>                {
>
>
>                    var q = s.Query<Foo>().Where(f => f.Module ==
> "bar");
>                    var list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f => f.Module.Length>1);
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.StartsWith("b"));
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.EndsWith("r"));
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.Contains("a"));
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.ToUpper()=="BAR");
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f => f.Module.ToLower()
> == "bar");
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.Substring(1, 1) == "bar".Substring(1, 1));
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f =>
> f.Module.IndexOf("r") == "bar".IndexOf("r"));
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f => f.Module==null);
>                    list = q.ToList();
>
>                    q = s.Query<Foo>().Where(f => null==f.Module);
>                    list = q.ToList();
>
>                    t.Commit();
>                }
>            }
>
> --
> You received this message because you are subscribed to the Google Groups
> "NHibernate Contrib - Development Group" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhcdevs%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhcdevs?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhcdevs?hl=en.

Reply via email to