I need to convert this SQL to Linq I dont' know how..
INSERT INTO #retCluster (HCIS_ID)
SELECT HCIS_ID FROM OHCD_EmployeeInfo
WHERE ImmediateSupervisor IN (SELECT HCIS_ID FROM #retCluster)
AND HCIS_ID NOT IN (SELECT HCIS_ID FROM #retCluster)
AND HCIS_Status_ID = 1
LINQ does not support inserting records in your database.
As the name says is for Query purposes only (right now); You cannot delete, update or insert. You need to rely on a DbContext or ObjectContext (EF) or DataContext (L2S) tables functionality to execute these operations on the tables mapped to your database after you have pulled the entities from the database.
There are extensions to entity framework that allow lambda based functionality to execute update or delete commands by passing expressions.
Also in your case, your Context needs to have knowledge about the variable table #retCluster which is not possible. You can still use DbContext.Database.SqlQuery method to execute any string based command in your database using the DbContext connection.
Related
For Instance
Suppose You have multiple tables Like these!
**Students(StudId, Sname, SRegNo),
Lecturers(LectId, LectName, Lect Course),
Courses(CourseId, CourseName, Coursemarks)**
How can you Join them by Getting only, Sname, Lectname and CourseMarks
I got an SQL injection point which allows me to insert anything after a Select keyword , such as :
Select ID FROM %INJECTION POINT%
is there anyway to complete this query to make an update for a table ? without using a ";" ?
It's not possible to do this in oracle , unless you use an existing user function to do so
What is the use of Table-CAST and CAST-Multiset?
Example of Table-Cast
SELECT count(1)
INTO v_Temp
FROM TABLE(CAST(Pi_Save_Data_List AS Property_data_list))
WHERE Column_Value LIKE '%Contact';
Example of Cast-Multiset
SELECT e.last_name,
CAST(MULTISET(SELECT p.project_name
FROM projects p
WHERE p.employee_id = e.employee_id
ORDER BY p.project_name)
AS project_table_typ)
FROM emps_short e;
What isthe performance gain or impact on the code?
The TABLE() function casts a nested table type to a relational result set. This is allows us to query a previously populated collection in SQL.
The CAST(MULTISET()) function call converts a relational result set into a collection type. This is primarily of use when inserting into a table with column defined as a nested table.
Few sites employ object-relational features in their permanent data structures so the second usage is pretty rare. But being able to use collections in embedded SQL statements is a very cool technique, and widely used in PL/SQL.
I have been using SQL Server 2008 for a short time now and have never used Oracle before. I am able to access an Oracle table through SQL Server with the syntax
select * from [OracleDB1]..[OracleDB1].[Zips]
(where OracleDB1 is the oracle database and Zips is the table I require)
Is it possible to join a SQL Server table with this one in a Table-valued Function? Just using a normal join as I would with SQL Server tables gives an Invalid object name error on the Oracle table.
Can this be done directly (or at all) or is it possible to do this some other way such as table variables?
example query:
select * from dbo.Table1 t INNER JOIN [OracleDB1]..[OracleDB1].[Zips] z where t.zip = z.zip
I was performing the join wrong since I missed the ON clause. I was able to get it to work by declaring a temptable and joining on that.
declare #tempTable table{
ZIP nvarchar(5),
COUNTY nvarchar(10)
}
insert #tempTable select ZIP, COUNTY, from [OracleDB1]..[OracleDB1].[ZIPS]
select * from dbo.Table1 t INNER JOIN #tempTable z on t.ZIP = v.ZIP where t.AdmissionOn >= '08-08-2011' AND t.AdmissionOn <= ''09-08-2011'
This also worked in line as I had in the original question once I added the ON clause but the table variable suits my needs better since it only has to access the Oracle table once and not each comparison.
yesterday I've been trying to make this code work inspite the fact it's just working fine with nhibernate and SQL server but when it come to oracle it generate wrong sql
UnitOfWork.Current.CreateCriteria<Bill>().Add(Restrictions.IsEmpty("ReqId"))
.SetMaxResults(BatchSize).SetLockMode(LockMode.Upgrade).List<Bill>();
the generated SQL will something like
Select * from
(Select bill_0.id,bill_0.BillNo ...... from Bill bill_0 where bill_0.reqId is Not null )
where ROWNUM < 10 for UPDATE of bill_0.ID
so i wont run because the allies bill_o is defined inside the inner sql statement so who got the solution ?
the correct sql would be something like this which i tried and worked on oracle db
Select bill_0.id,bill_0.BillNo ...... from Bill bill_0
where bill_0.reqId is Not null and ROWNUM < 10 for UPDATE of bill_0.ID
Since, as you say, NHibernate is generating invalid Oracle SQL, I suggest you file a bug with the NHibernate people. The SQL would work if the in-line view had been assigned an alias of "bill_0", or if the FOR UPDATE clause didn't use a table alias ("for UPDATE of ID"). Whether you can modify your NHibernate calls to make either of these happen I'm afraid I have no idea.