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.
Related
Is there are way to detect what type of database currenlty is in use as project datasource?
Because I need to get some inner scripts information. And, in case of simple .EAP project, SQL-query would look like (because of Access db in use):
_repository.SQLQuery(string.Format(#"SELECT * FROM t_script WHERE Notes LIKE '*Script Name=""{0}""*';", scriptName));
But, in case of SQL server I need to execute (as you already guessed I bet) slighly different written query:
_repository.SQLQuery(string.Format(#"SELECT * FROM t_script WHERE Notes LIKE '%Script Name=""{0}""%';", scriptName));
So, is it possible?
UPD:
I found one option - looks like there are _repository.ConnectionString property which could be parsed
"SparxEaDatabase --- DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SparxEaDatabase;Data Source=SOURCENAME;LazyLoad=1;"
Is there are more?
I would just look into Repository.RepositoryType. This will return for Example: JET, MYSQL, or SQLSVR.
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.
According to this issue:
https://nhibernate.jira.com/browse/NH-3038
NHibernate should create efficient paging queries for SQL Server 2012.
I have NHibernate 3.3.3GA. I set the dialect in the config file:
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
and while debugging I see that indeed the session factory has MsSql2012Dialect.
But still the following code:
session.Query<TestEntity>().Skip(1).Take(1).ToList()
generates the same T-SQL as the old SQL Server 2008 dialect does:
exec sp_executesql N'
SELECT TOP (#p0) EntityId1_, Version1_, Name1_, Something1_
FROM (select testentity0_.EntityId as EntityId1_, testentity0_.Version as Version1_, testentity0_.Name as Name1_, testentity0_.Something as Something1_, ROW_NUMBER()
OVER(ORDER BY CURRENT_TIMESTAMP)
as __hibernate_sort_row from tTestEntity testentity0_) as query
WHERE query.__hibernate_sort_row > #p1
ORDER BY query.__hibernate_sort_row',N'#p0 int,#p1 int',#p0=1,#p1=1
How do I make NHibernate Linq provider to use the paging features of MsSql2012Dialect and generate a query with OFFSET and FETCH?
Solution:
Thanks to Diego Mijelshon who led me to the right source code, I managed to implement a quick fix which seems to work fine. We are using it for some months already, no problems yet.
Here is what I did:
I imported the following classes from the NHibernate source into my own library:
https://github.com/nhibernate/nhibernate-core/blob/967091f5c22a16a576f46144055f78c0f373ffcd/src/NHibernate/SqlCommand/Parser/SqlTokenizerExtensions.cs
https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Dialect/MsSql2012Dialect.cs
https://github.com/nhibernate/nhibernate-core/blob/967091f5c22a16a576f46144055f78c0f373ffcd/src/NHibernate/SqlCommand/Parser/SqlTokenizer.cs
https://github.com/nhibernate/nhibernate-core/blob/967091f5c22a16a576f46144055f78c0f373ffcd/src/NHibernate/SqlCommand/Parser/SqlParserUtils.cs
https://github.com/nhibernate/nhibernate-core/blob/967091f5c22a16a576f46144055f78c0f373ffcd/src/NHibernate/SqlCommand/Parser/SqlToken.cs
As far as I remember, I did some modifications to remove unnecessary bits of code.
In SqlTokenizerExtensions I left only these two extensions:
public static bool TryParseUntil(this IEnumerator<SqlToken> tokenEnum, string keyword)
public static bool TryParseUntilFirstMsSqlSelectColumn(this IEnumerator<SqlToken> tokenEnum)
SqlTokenizer, SqlToken, SqlParserUtils, MsSql2012Dialect - no changes.
Then I just set <property name="dialect"> to the new MsSql2012Dialect in my config file for NHibernate, and now my paging queries are clean and simple.
If you look at NH-3038, you'll see that it's fixed in master/vNext. That means NH4.
You can still get the updated dialect from https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Dialect/MsSql2012Dialect.cs, include it in your project and reference it (adding the correct assembly name).
I'm using NHibernate 3.1 with FluentNHibernate 1.2.0.712.
We're using the HiLo generator to generate Ids - with standard settings except max_lo is set to 100 (default 1000).
Our mappings all have this line in the ctor:
Id(m => m.Id)
.GeneratedBy.HiLo("100");
Hovewer, when we start fresh with a new SessionFactory, and the first item is saved - let's say the next hi is 12 it gets Id 1212 (I would have expected 1200 or 1201). Is this intended behaviour or am I missing some vital part of the configuration?
I've tried using default values ("1000") as the max_lo, but then the above would result in 12012 - still not exactly what I would expect.
I read through the nhibernate code-base. This is apparently intended behaviour - for the initial set, it 'clocks over' (for a reason beyond me - but probably has something to do with keeping parity with hibernate (since that has that exact same comment :-)).
For all subsequent increments - all is performing as expected.
So, closing down this question.
I have sample application on Nhibernate with Nhibernate Search with the following version nos,
Nhibernate - v2.0.0.1001
Nhibernate Search - v2.0.0.1001
I am not sure if it custom build, but everything seems to work fine here. But as soon as I change the Nhibernate version to v2.0.1.4000 (a later minor version and build), things start breaking at,
IList result = s.CreateCriteria(typeof(DomainObject)).Add(NHibernate.Search.Search.Query("Summary:NHibernate or Name:NHibernate"))
VStudio complains "'Query' is not supported language."
Has anyone had a similar issue? How could I get a port for v2.0.1.4000?
Thanks.
I guess the way to create a lucene query was to just use the Query Parser:
QueryParser queryP = new QueryParser("id", new StandardAnalyzer());
Lucene.Net.Search.Query q = queryP.Parse("Summary:NHibernate or Name:NHibernate");
IList result = s.CreateFullTextQuery(q, typeof(DomainObject)).List();