linqpad + linq2sql custom model - linq-to-sql

I'm trying to get LinqPad use my dbml model so I could analyze a query from my source code. I've set the DataContext to "Custom LINQ to SQL DataContext", and all the necessary settings, unfortunately even with the simplest query I get an error :
QUERY: from m in Linia select m
ERROR: Could not find an implementation of the query pattern for source type 'MyNameSpace.Linia'. 'Select' not found.
Does anybody know how to get this to work? Thx!

Found it! By default, LINQPad pluralizes table properties in the DataContext. I should have used Linias instead of Linia.

Related

SQLAlchemy - Unable to reflect SQL view

I'm getting the following error message when trying to reflect any of my SQL views:
sqlalchemy/dialects/mysql/reflection.py", line 306, in _describe_to_create
buffer.append(" ".join(line))
TypeError: sequence item 2: expected str instance, bytes found
I have tried using both the autoload_with and autoload=True options in my select query constructor to no avail.
I have the appropriate permissions on my view. My query is pretty simple:
company_country = Table('company_country', metadata, autoload_with=engine)
query = select(company_country.c.country)
return query
I've tried the inspect utility and it does not list my SQL view, nor does the reflecting all tables described below the views section on this page: https://docs.sqlalchemy.org/en/14/core/reflection.html#reflecting-views
I'm using version SQLAlchemy->1.4.32, Python 3.x and mySQL 8.0.28 on Mac if that's any help
I should add that I can query my SQL views using the text() constructor but it would be far more preferable to use select() if possible.
Any tips appreciated
I was using the mysql-connector client for interop with other code, but after switching to the mysqlclient, I was able to reflect the views.
https://docs.sqlalchemy.org/en/14/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqldb

Entity Framework Core Linq query doesn't translate to correct SQL statements

So I am debugging our application which uses Entity Framework Core 2.1.14. I created my entities from database first by scaffolding. Database is MySQL 5.7.29, the SQL data provider for EF Core is Oracle's MySql.Data.EntityFrameworkCore 8.0.19.
Example: a simple Linq query should create a proper SQL statement in the backend. However it does not. "Inactive" is a Byte?.
Dim associates = (From a In DatabaseContext.Associate
Where a.Inactive = 0
Select a.AssociateId).ToList()
This simple Linq query returns: SELECT `a`.`Inactive`, `a`.`AssociateID` FROM `associate` AS `a`. So basically it downloads all associates and does the "where" in memory and returns the values. I know according to the documentation some queries can be complicated and can't be translated, but this is a simplest of the simple queries. Is it because the Inactive column is nullable? Something is terrible not right.
FYI: EF Core is in a class library that is C#. The VB code is in another project that is VB that references the class library.
Hmm, seems the answer is to make the query more specific in VB. I guess the query conversion between C# class library and VB project seems to be the issue.
Dim associates = (From a In DatabaseContext.Associate
Where a.Inactive.Value = Convert.ToByte(0)
Select a.AssociateId).ToList()
This provides the correct query:
SELECT `a`.`AssociateID`
FROM `associate` AS `a`
WHERE `a`.`Inactive` = 0
Very weird that in C# you don't have to check against the .Value and convert the 0 to a byte but in VB I had to do it, there was no other way to get it work. Thanks for everyone trying to help with this.

SIMILAR TO predicate ingres 4gl issue

I used this query to get a regular expression with successful results.
select * from paso_string where 'AAAAAAAAA' SIMILAR TO columname
But, When I use this query into ingres 4GL show me an error when I try to compiling and show me the follow issue.
E_OS0100 Syntax error on line
The last symbol read was 'similar'
4GL has its own parser, which sadly is often behind the SQL parser when it comes to new features.
The standard work-around is to put your SQL statement into a string and then do execute immediate :string;

mysql - what does a : before a value in sql mean?

I'm a noob with sql and trying to figure my way through zencart. There's a bit in the code where it prepares a SELECT statement and amongst that there is the following line:
AND cd.language_id = :languagesID
I can't figure out what the : does. I thought maybe it refers to a $variable like $languagesID but I can't find that variable anywhere either.
What does the : do? Google left me none the wiser.
It's for prepared SQL statements. It's replaced later on with an actual value. Google "Prepared SQL"

how to use string left function in hql

I have a sql query like this
select column from table where path = left('INPUTSTRING', length(path));
and trying to accomplish it in hql like this,
return session.createQuery("from Table where Path = left(:input, length(Path))").
query.setParameter("input", inputPath).
.list();
and getting an error like this
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: left near line 1
how to get this done? What is the corresponding string function in hql? Is there a solution for this using criteria query apis?
Yes, left() is not supported by the MySQLDialect. See the list of HQL supported functions on API docs.
Now you have left with 2 options.
Use session.createSQLQuery() method.
Create Your own Dialect class by extending the MySQLDialect and register the function there. This is told at hibernate forum here explained well in a blog post here.
I'm not sure if HQL does this for you , but you can use IQuery/session.CreateSQLQuery() to use a raw SQL query to populate a mapped entity. I've never used it for substrings, but have used it for aggregate functions. Check chapter 13 of the NHibernate docs and see if that does it for you. You can check the query substitution available in Nhibernate - here