EF Code First Cascade Delete not working - vb.net

I have this model definition and I want to cascade delete on it.
With modelBuilder.Entity(Of dbDimension)()
.Property(Function(t) t.dbDimensionID).
HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.HasKey(Function(t) t.dbDimensionID)
.Property(Function(t) t.Name).
HasColumnName("DimensionName")
.ToTable("Dimension")
modelBuilder.Entity(Of dbDimension)().
HasRequired(Function(t) t.Model).
WithMany(Function(t) t.mDimensions).
HasForeignKey(Function(t) t.dbModelID_FK).
WillCascadeOnDelete(True)
modelBuilder.Entity(Of dbDimension)().
HasMany(Function(t) t.Cubes).
WithMany(Function(t) t.Dimensions).
Map(Sub(m)
m.ToTable("Dimension-Cube")
m.MapLeftKey("dbDimensionID")
m.MapRightKey("dbCubeID")
End Sub)
End With
at the moment when I delete model, dimensions get deleted as well but the many to many relationshipt doesn't get deleted.
What can I do to fix this?
I'm using Dotconnect (SQLLite) as db driver.

Foreign key support is not enabled in SQLite by default. You need to enable it, for example by adding "Foreign Key Constraints=On" to your connection string:
Data Source=test_data.db;Foreign Key Constraints=On
If it is not the case, please send us a test project to support at devart*com , so that we are able to investigate the issue and find the solution for you.

Related

How can I get Rails 5 to play nicely with a primary key that has a period in it?

I'm working with a database I have no control over, and cannot make alterations to. This database has a table called warehouse_items. Each warehouse item is uniquely identified by a primary key indicating the item id.
Unfortunately, that primary key attribute is named WAREHOUSE_ITEM.ID
(Note the obnoxious period between "item" and "id")
When I try to run a basic query, such as:
WarehouseItem.find('wh3453')
I get an Undefined Table error.
Fortunately, when looking at what Rails is attempting to do, the problem becomes obvious:
: SELECT "warehouse_items".* FROM "warehouse_items" WHERE "WAREHOUSE_ITEM"."ID" = $1 LIMIT $2
Because of the period in the attribute name, Rails is treating "WAREHOUSE_ITEM.ID" as a table/attribute combination, rather than an attribute name with a period in it.
When I run the following PSQL query by hand, I get exactly what I need:
SELECT "warehouse_items".* FROM "warehouse_items" WHERE "warehouse_items"."WAREHOUSE_ITEM.ID" = 'wh3453'
Why is Rails screwing this up, and how can I fix it?
EDIT:
Also worth noting: I've tried using self.primary_key to override the primary key to no avail.
I've tried both a string and a symbol, as in:
self.primary_key="WAREHOUSE_ITEM.ID"
and
self.primary_key=:"WAREHOUSE_ITEM.ID"
Neither one has worked...
Thanks for all the help, everyone!
A suggestion in the comments to use find_by_sql does work! However, I stumbled onto a different solution that works even better.
First, I aliased the annoying attribute name to something simple: id
alias_attribute :id, :"WAREHOUSE_ITEM.ID"
Notice that it's still a symbol, which is important for the next step.
I then overwrite the primary_key method with a custom function:
def self.primary_key
return "id"
end
Now, when I do WarehouseItem.find('wh3453'), Rails defaults to checking id, which is aliased to the correct symbol and it works as intended!!!

EclipseLink does not generate terminate statement for OraclePlattform

When generating the schema generation script, the terminate statement ";" is generated correctly when using a h2 database, but no terminate statement is generated for oracle. (eclipselink.ddlgen-terminate-statements is set to true)
Is there any way to make eclipselink generate ";"? Really want to avoid going through the script afterward and add ";" manually...
I found a workaround here shortly after having posted the question.... Basically,
Create a subclass of OraclePlatform
set the protected field storedProcedureTerminationToken to ;
Use its qualified name for the property eclipselink.target-database

UPDATE on UIText table fails

I am trying to update the UIText Table in a Windows Installer database (.msi)
My program has already updated many tables and fields within the .msi
I am opening the database as such:
MsiOpenDatabase(this->MsiFile,MSIDBOPEN_DIRECT,&this->MsiHandle);
This returns
ERROR_SUCCESS
I have updated ~200 records in various tables (Control.Error,Feature,Shortcut,...), all of the updates work.
then I get to:
MsiDatabaseOpenView(this->MsiHandle,L"UPDATE UIText SET UIText.Text='Entire
feature will be unavailable' WHERE (UIText.Key='MenuAbsent')",&ViewHandle)
This returns
ERROR_BAD_QUERY_SYNTAX.
I have tried:
L"UPDATE 'UIText' SET 'UIText'.'Text'='Entire feature will be unavailable'
WHERE ('UIText'.'Key'='MenuAbsent')"
and get the same result
ERROR_BAD_QUERY_SYNTAX.
What am I missing here?
Darn! Sorry about the waste of time.
L"UPDATE UIText SET UIText.Text='Entire...' WHERE (UIText.'Key'='MenuAbsent')
Works.
I was confused over the use of 'back ticks'
Key is an SQL reserved word.
UIText.Key is not valid.
UIText.'Key' is also not valid. This is using apostrophes (39 Decimal) around Key.
UIText.Key is valid. This is using 'back ticks' (96 Decimal) around Key.

Yii framework - picking up field value from other model

I have been struggling with this, i have two models and showing data in Cgridview with one model, this model contains some id's whose values are in different table
So, i have added
'value'=> 'TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw'
which is giving this error
"Trying to get property of non-object"
Might be due to this reason that the some records doesn't exist in the TblAreaoflaw. Can't we check in this line through isset?
When i put static value, it work well, like
'value'=> 'TblAreaoflaw::model()->FindByPk(5)->areaoflaw',
Could anyone please help
thanks a lot
The error you get is because this expression TblAreaoflaw::model()->FindByPk($data->typeoflaw) is returning null. This means that you are effectively trying to get null->areaoflaw which won't work (this is what the error message "Trying to get property of non-object" clarifies).
My best guess is that $data->typeoflaw returns a non-existing primary key for the TblAreaoflaw model.
Make sure :
TblAreaoflaw is actually a model, I doubt its Areaoflaw
You have database specified primary key which is the id (5) you are passing
Try:
'value'=> '(TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw) ?
: "default or null value"'
Obviously substitute the null string to whatever you want. You may need to adjust the condition to use !empty() or similar, but see how it goes. (And if you do that or aren't using PHP 5.3, use the full ternary expression.)

Ideablade Update

I'm using IdeaBlade version 3.6. I noticed the following generated SQL update query :
(#P1 nchar(32),#P2 nvarchar(32),#P3 nvarchar(512),#P4 nchar(32),#P5 int,#P6 nvarchar(32),#P7 int,#P8 datetime,#P9 datetime,#P10 datetime,#P11 int,#P12 datetime,#P13 int,#P14 int,#P15 int,#P16 nvarchar(32),#P17 nvarchar(128),#P18 nvarchar(32),#P19 nvarchar(32),#P20 datetime,#P21 datetime,#P22 bit,#P23 nvarchar(32),#P24 nvarchar(64),#P25 nchar(32))update "dbo"."GSS_Documents" set "DocumentID"=#P1,"FileName"=#P2,"FilePath"=#P3,"BusinessOfficeID"=#P4,"Pages"=#P5,"FileSize"=#P6,"DocumentType"=#P7,"DateCreated"=#P8,"EffectiveDateCreated"=#P9,"DateProcessed"=#P10,"ProcessorID"=#P11,"DateReviewed"=#P12,"ReviewerID"=#P13,"WorkflowStatus"=#P14,"ApprovalStatus"=#P15,"AccountNumber"=#P16,"AccountName"=#P17,"SerialNumber"=#P18,"TransactionID"=#P19,"CriticalDate"=#P20,"EmergencyDate"=#P21,"GenerateSMSAlert"=#P22,"CustomerPhoneNumber"=#P23,"CustomerEmailAddress"=#P24 where "DocumentID"=#P25
Problem is DocumentID is the primary key. This update appears to be updating the primary key as well! Any ideas on how to stop this?
You're using Entity Framework in this example and we don't tell EF how to do its job. Perhaps you're changing the PK (I rather doubt it). Follow up with us directly ... especially with regard to DevForce 2010 which relies on EF v.4.