|
Obviously more than a "simple" query. LINQ is confused (as would most looking at your query). Simplify and work with "intermediate" results (to confirm your expectations) instead of relying "one size to fit all" and luck.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I resolved it the following way, but any suggestions I am open to take:
var Violations = (from v in UnitOfWork.ViolationRepository.GetAll()
join a in UnitOfWork.OneToManyRepository.GetAll().Where(a => a.ParentEntity == "Notice" && a.ChildEntity == "Violation")
on v.ViolationId equals a.ChildEntityId
join b in UnitOfWork.OneToManyRepository.GetAll().Where(a => a.ParentEntity == "Notice" && a.ChildEntity == "Case")
on a.ParentId equals b.ParentId
where b.ChildEntityId == caseId
orderby v.ViolationId
select v).ToList();
|
|
|
|
|
Hi I have 3 Tables Cases, Programs, Violations, now all these Tables are related as ManyToMany with Notice Table, but earlier they were having OneToMany, but now they are related ManyToMany, hence I moved them all to the Associated Table to handle it, which is called as ManyToMany table which has PK, ParentyEntity, ParentEntityId (which is PK of Notices table), ChildEntity, ChildEntityId - I have to do it with Entity Framework Code First Migrations - hence I am trying to be very cautious here. What am I planning are 1.Take backup of the Database 2. Migrate Data from tables to ManyToMany table 3. Record all the Foreign Key Constraints first (like generate scripts for those FKs references) then drop all those Foreign Keys 4. Then Drop tables using Entity Framework Code First Migrations.
Can somebody please help me if I am missing anything and are there any easy fool proof ways to do the same and how to drop columns using Entity Framework Migrations - I have lost touch with Code First approach, I understand its tough and needed very careful implementation - any suggestion any help would be very very helpful. Actually the Database has already have been implementing this - but they didn't drop the old columns and didn't delete the data from old columns - hence its creating or showing inconsistent Data, the old programmer has left it in between - need a lot of suggestions and support - thanks a lot.
|
|
|
|
|
"Code First" is "easy"; it's hard when you're thinking about "conversion" when still developing a data model. The final model drives the conversion process ("ETL"); not the other way around.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Can you please elaborate a little bit buddy?
Gerry Schmitz wrote: "Code First" is "easy"; I understood that
Gerry Schmitz wrote: it's hard when you're thinking about "conversion" Which conversion?
Gerry Schmitz wrote: when still developing a data model The Data model is already developed, I am maintaining the application, I am scared if I drop the column from Code, it will drop that column permanently from Database and how am I going to migrate the data? I think I will have to write my own scripts for it, am I correct my friend? Any detailed suggestions or links anything helps my friend - but even for this I thank you for taking your time to answer my queries - its a great help.
Gerry Schmitz wrote: The final model drives the conversion process ("ETL"); not the other way around
I didn't really get this, means ETL should migrate the Data how? - thank you my friend.
|
|
|
|
|
Hi, unfortunately I have deleted the tables that are created by entity framework Code first migration file manually, now when i am running the migrations or add migration file, its throwing error when running the Update-Database command. What can I do for it now?
Can you please help me in this regards buddy? I have the copy of the Deleted migration file, but its not running its giving compile error if I try to run. Can I delete all those tables that are created by running the previous migration file, clean it up and create new fresh migration file and run update database - any-help would be very very helpful. Another problem I tried to run the migration file previous to that of deleted migration file to restore to previous stage - since it could delete the records - that's also not running - any help please to make again fresh start by deleting the newly created tables and create new migration file and run update database.
|
|
|
|
|
Hi, I have a Linq query as follows
NOVId = (v.NOVId != null ? new List<int> { v.NOVId ?? default(int) }
: (from n in novs where n.Violations.Any(a => a.ViolationId == v.ViolationId) select v.NOVId ?? default(int)).ToList())
, what I want is, it is failing at n.Violations or a.ViolationId, since there are some novs which do not have violations, how can I fix this? that it shouldn't fail, just goes through without errors or exceptions - means this shhould select only if n.Violations has violations otherwise just return either 0 or null - any help please? Thanks in advance.
And in similar way I have a Linq query in the following way, where if some value becomes null within from, then avoid the select
Violations = from vv in n.Violations
select new
{
ViolationNumber = vv.ViolationNumber,
ViolationId = vv.ViolationId,
inspectionItemNum = (inspectionItems != null && inspectionItems.Count() > 0) ?
(from i in inspectionItems where i.Violations.Any(v => v.ViolationId == vv.ViolationId) select i.InspectionItemNumber)
: null
}
So in the above Linq query, if the vv becomes null, I don't want select new to be executed as it is going to throw exception, how can I handle this situation in C# - thanks again.
modified 15-Nov-19 21:22pm.
|
|
|
|
|
If you want us to help you fix an error, you need to tell us what the error is.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi everyone, I created a library of the WCF service, which recalls a VB6 dll.
The problem is this: in the procedures of the VB6 dll (not my owner) strange errors occur (especially with dates), if the initial process that hosts it is the WCF service.
Everything works correctly if the initial process is a VB6 executable, a VB.NET executable, or if I run the VB6 project in debug.
Among the many attempts I set all my projects with CPUs targeting x86, and although I had no problems compiling the WCF service, I also tried to replace WcfSvcHost.exe with the same in 32-bit mode (with the command "corflags / 32BIT + / FORCE WcfSvcHost.exe "), but the problem persists.
Actually I don't think it's even necessary, as the hosting of the WCF library is an application console.
I have no idea how to solve ... can anyone help me?
|
|
|
|
|
Emanuela Meraglia wrote: strange errors occur Please don't keep them secret.
|
|
|
|
|
I don't have the error because the VB6 dll is not mine, but with SQL profiler I found errors in the queries due to lack or incorrect formatting of dates.
|
|
|
|
|
You're going to need to provide more details on the errors you're getting.
My guess would be something to do with the regional settings for the session that's hosting your WCF service. But without any details, it's just a guess.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't have the error because the VB6 dll is not mine, but with SQL profiler I found errors in the queries due to lack or incorrect formatting of dates.
|
|
|
|
|
Emanuela Meraglia wrote: errors in the queries due to lack or incorrect formatting of dates
That would suggest that the VB6 code is vulnerable to SQL Injection[^]. It it was using properly parameterized queries, date formatting wouldn't be an issue.
This is a serious security vulnerability. You should either get the author to rewrite the VB6 code, or find some way to replace it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
They are rewriting it, but in the meantime I have to use their dll VB6!
|
|
|
|
|
The error also occurs on my development PC, on which everything is executed. So I don't think it's a problem of regional settings.
|
|
|
|
|
Let us reverse Engineer it, I have come across these types of situations a lot time ago.
Here is the clue, you said you are able to execute the application and the same dll as exe right? Check what Date formatting is it being used there and one more advice is, go to the stored procedure because you are able to find the stored procedure using the SQL Profiler right? Try to execute the SP by passing the different Parameters and replicate the same error, then you would know what formats the SP is accepting and what formats the sp is giving the errors and why?
Then you can fix the issue in the Web Service to use the same format - what you are going through is similar what many have sometime back when everything moved from VB6 to .Net Framework - but its OK.
You are doing a great Job - best of Luck.
|
|
|
|
|
Does it run under the same user credentials as a normal executable?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I start the service without credentials:
<pre>Private Sub AvviaServizio(ByVal t As Type, ByVal uri As String, ByVal classe As String)
Dim binding As New BasicHttpBinding
binding.OpenTimeout = New TimeSpan(0, 10, 0)
binding.CloseTimeout = New TimeSpan(0, 10, 0)
binding.SendTimeout = New TimeSpan(0, 10, 0
binding.MaxBufferPoolSize = 2147483647
binding.MaxBufferSize = 2147483647
binding.MaxReceivedMessageSize = 2147483647
binding.MessageEncoding = WSMessageEncoding.Text
Dim host As New ServiceModel.ServiceHost(t)
host.AddServiceEndpoint(classe, binding, New Uri(uri & classe))
Try
host.Description.Behaviors.Add(New ServiceMetadataBehavior With {
.HttpGetEnabled = True,
.HttpGetUrl = New Uri(uri & classe)
})
host.Open()
_service.Add(host)
Catch ex As Exception
host.Abort()
Throw
End Try
End Sub
|
|
|
|
|
That doesn't answer my question; write the name of the current user to a logfile or similar to check.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I don't understand which user you're referring to
|
|
|
|
|
Environment.UserName
All the code runs under specific credentials. Your hosted service may not be running as a default user.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I wrote the current user in my log file, and it matches with the Windows credentials I logged in with ... so it's ok.
|
|
|
|
|
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
VB6 can only make COM-exposed .DLL's. I don't know if that means or affects anything, but there it is.
Without seeing the code that's calling the functions in the .DLL, and the error messages coming back from SQL Server, it's going to be impossible to tell you anything useful.
The biggest problem is we can see the code in the VB6 .DLL, so we don't know what it expects in the function calls.
|
|
|
|