Entity-Framework -> MySql gives 'Function evaluation timed out.' - mysql

I having a weird problem with Entity Framework with MySql database.
Here's the code that I've got.
public class testbase
{
private testEntities db = new testEntities();
public IQueryable<post> GetRecords()
{
return db.record;
}
}
Here record is a table in my database and this could should return all the rows in the table. I have only one row in there and when I do a db.record.Count(), I get 1.
But when I try to retrieve the rows themselves I get 'Function Evaluation timed out'.
What's happening? Anybody got any ideas?

Okay, this turned out to be a dud question. Ben M was right. Some googling revealed: -
EF does not behave well while debugging due to some issues in VS debugger. You get a 'Function evaluation timed out'.
Things work swell when you try the code without debugging.
I was testing as I go for my new EF+MySql+ASP.Net.MVC app, and since I am a n00b at all three I didn't realize that.
I haven't deleted the question yet because there for others like me. It's on the community to decide whether to let this question survive or go.
I pronounce this question officially a dud.

Related

PowerBuilder Find function throws an error "expression is not valid"

What is wrong with this code. I am checking whether there is an available record in the database before inserting a new serial number. When I enter any record whether available or not, it throws an error message:
"Expression is not valid". (PowerBuilder Classic 12.5 and SQL Server
2008)
If This.GetColumnName() = "serial_No" Then
long ll_serial
ll_serial=dw_newrecord.find(data, 1, dw_newrecord.rowcount())
if ll_serial>0 then
messagebox("validation error", "The record already exists")
return 1
end if
End If
It is likely that your data expression has a syntax error. It can be some misformed code -like missing quotes- or maybe that the column name is incorrect.
To help for tuning a filter or find expression, you can test it in the datawindow design screen via the Rows / filter menu.
A better solution for long-term coding design would be to integrate the Datawindow Debug Machine (made by a colleague of mine) to your project. It is a precious tool to prototype datawindow expressions for finding, filtering but also for dynamic objects creation / modification in a datawindow. And while correctly interfaced with a datawindow ancestor of your project, it can help with filters and find expression errors like here.
EDIT: As RealHowTo noticed, the tool has been updated. Here is the current latest version (but there is no updated demo screencast though).

Linq to SQL "Cannot insert the value NULL" when NOT NULL!

I am massively in need to help. I have spent an entire day when I do not have even an hour to waste on a project. I have a Linq to SQL data layer and am doing a simple insert into the DB using the following code:
using (var odc = new OrdersDataContext())
{
try
{
var id = GetNextOrderId(odc);
order.ID = id;
odc.tblOrders.InsertOnSubmit(order);
odc.SubmitChanges();
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
Due to other legacy code and this being a database that is running on SQL 2000 I cannot make database alterations, but this code was working fine at one point and then simply stopped working. It is saying that :
Cannot insert the value NULL into column 'ID', table 'Order'; column does not allow nulls. INSERT fails.
But as you can see from the code and what I can CLEARLY see as I step through the code, the ID column is getting a valid ID number. For some reason even though I am setting the ID field it is attempting to insert it as a null even though this code was working fine before. I've gone so far as to completely restore the database and rebuilt the data layer, but to no avail.
I'm so stumped on this and out of time that I'm beside myself.
So, the answer to this is very strange and I'm not 100% certain of why. Essentially what I did was completely rebuild the LINQ to SQL data layer (merely dragging and dropping the same tables in the designer) and then completely cleaning and rebuilding the entire solution. After that the code magically worked again. No code change required.
For some reason the code was improperly cached and that caused it to not be able to transfer the object to the data layer (is my guess). It seems like a strange error to get back in that case.

Linq to SQL - Submit Changes not adding to database

I have this pretty simple method:
internal void Add(RecipeRecord recipeRecord)
{
this.Database.GetTable<RecipeRecord>().InsertOnSubmit(recipeRecord);
this.Database.SubmitChanges();
}
The entity I'm inserting is a valid entity. When I call SubmitChanges, nothing happens. No errors and no row added to the database. There is no transaction active. If I call GetChangeSet() on the context object, I see the single entity to add. After SubmitChanges(), the change set is empty.
Can anyone see what might be wrong?
I think you may have to use context.attach I ran in to a similar issue and that got me going in the right direction.

Linq-to-SQL best practices: Deleted entities not really being deleted

Being new to Linq-to-SQL, I ran into one of it's Gotchas today and I wanted to share my solution and then ask if there was something better.
I'm setting up a staff allocation tool for my work. There are three basic class/tables: Employee, Project, Assignment. Importantly here, Assignment serves as a junction table between Employee and Project. I ran into my problem on a form that contained a DataGridView that was bound to a BindingList. The problem came when a user decided to create a new assignment, but then before saving their changes they decided to delete the new assignment that they had just created. Unfortunately, saving caused the deleted assignment to be saved anyhow!
Here is a (somewhat simplified) version of my naive delete handler:
//Assume that assignments is the BindingList<Assignment> bound
//to the dataGridView
private void DeletedRowHandler(object sender, EventArgs e)
{
DataGridViewRow row = dataGridView.GetSelectedRow();
Assignment assignment = (Assignment) row.DataBoundItem();
assignments.Remove(assignment);
try
{
db.Intervals.DeleteOnSubmit(assignment);
}
catch
{
}
}
After much weeping and gnashing of teeth, it occurred to me that through the magic if Linq-to-SQL, the Employee and Project which the deleted assignment had been associated with already had a reference to the Assignment that I thought I was deleting. This was causing it to be submitted to the database eventually.
The fix that I ended up using was to insert the following code in my delete handler:
assignment.Employee = null;
assignment.Project = null;
This appears to work.
My question: Is this what you're supposed to do? Or is there a cleaner approach that I don't know about?
Note: In writing this question I got a friendly, automated notice that this question was likely going to be closed. If you decide to close it, then please be kind enough to tell me why and to point me in a good direction.
Suggest deleting by ID, if you can. Let the DataContext find the entity by its key, and supply that entity to the Delete method.
DeleteAssignment(someRowID);
...
public void DeleteAssignment(int assignmentID)
{
db.Assignments.DeleteOnSubmit(
db.Assignments.SingleOrDefault(a=>a.ID==assignmentID)
);
db.SubmitChanges();
}

Linq 2 SQL on shared host

I recently ran into an issue with linq on a shared host.
The host is Shared Intellect and they support v3.5 of the framework. However, I am uncertain to whether they have SP1 installed. My suspicion is that they do not.
I have a simple News table that has the following structure:
NewsID uniqueidentifier
Title nvarchar(250)
Introduction nvarchar(1000)
Article ntext
DateEntered datetime (default getdate())
IsPublic bit (default true)
My goal is to display the 3 most recent records from this table. I initially went the D&D method (I know, I know) and created a linq data-source and was unable to find a way to limit the results the way I desired, so I removed that and wrote the following:
var dc = new NewsDataContext();
var news = from a in dc.News
where a.IsPublic == true
orderby a.DateEntered descending
select new { a.NewsID, a.Introduction };
lstNews.DataSource = news.Take(3);
lstNews.DataBind();
This worked perfectly on my local machine.
However, when I uploaded everything to the shared host, I recieved the following error:
.Read_<>f__AnonymousType0`2
(System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MethodAccessException:
.Read_<>f__AnonymousType0`2
(System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>)
I tried to search the error on Google, but met with no success. I then tried to modify my query in every way I could imagine, removing various combinations of the where/orderby parameters as well as limiting my query to a single column and even removing the Take command.
My Question therefore comes in 3 parts:
Has anyone else encountered this and if so, is there a "quick" fix?
Is there a way to use the datasource to limit the rows?
Is there some way to determine what version of the framework the shared host is running short of emailing them directly (which I have done and am awaiting an answer)
System.MethodAccessException is thrown by the framework when it is missing an assembly, or one of the references are of the wrong version.
The first thing I would do is try uploading and referencing your code to the LINQ assemblies in your BIN, instead of the shared hosting providers GAC.