sql server - Entity Framework: Linq !contains based on table from different database -


To use Entity Framework, I am trying to work around the fact that Linq can not be able to connect between tables from different databases. Database:

DB1.dbo.Table1: Id, XmlText

DB2.dbo.Table2: ID, Timestamp, Cola, ColB ...

I Table 2, where a property is set to True in XmlText, that is, 'xmlProp = true' in XmlText

In SQL, I just

 < Code [db2]. [Db2]. [Db2] [db2]. [Table 2] Inner join [DB1]. [DBO]. [Table 1] at [Table 1] IID = [Table 2]. IWWMEText '% xmlProp = true%'   

Since I can not use connecting with Linux (different database, remember?), I am doing:

  var query = from d1 to t1. Tables1 where db1.Text.Contains ('& lt; xmlProp & gt; incorrect & lt; / xmlProp & gt;) select t1.Id; Var sets = new hashets & lt; Guid & gt; (); Foreach (var elem in query) set.Add (elem); Var query2 = from d2 to T2 Where 2 Enabled! Select Set.Contains (t2.Id) T2;  

I can search for 'true' instead, but fewer lines are false so the set will be small, thus increasing the performance.

Now: Is there a better way to do this? Generating SQL queries on a large scale (a long list to avoid the ID ...), and it only feels stupid to store the ID in memory to pass back to the SQL server on the ID. anyone?

Thank you, M

You can use two DataContexts or you can Can set footage and 3-part nominations, if they are under the same server, so that a database can be called.

But as you said before, when you said that you can not find two references in a query, you can not meet them if you have a real execution.

You can use only two datacontacts which are meant to ensure that they are executed and brought before being included in the memory, and just join the institutions in memory I know that this To define execution is not as good as long as the actual calculation is not done until you are collecting lots of information in memory and being heavily filtering Because the collection is better than another passing once again, but this far you must answer correctly.

Just change the server, database and table name, whatever is in your environment.

Example where you refer to items from different contexts and it fails:

  refer to zero_in_on_on_coti () {constant string} Sc1 = "" server = YOURSQLSERVER; Database = DEVDATABASE1; Trusted Connection = True; "; Const String sc2 = @" Server = YOURSQLSERVER; Database = DEVDATABASE2; Relationalnection = true; "; (var dc = new data syntax (sc1)) ({var dc2 = new data contents (sc2)) {var users1 = dc.getTable & lt; user & gt; (); var users2 = Dc2.GetTable & lt; Users & gt; (); // You will get some error, which states that the data in the query is the context of the objects defined on the reference. Var has joined (in U1 User 1 has joined U2 on User 2 in U2, login is equal to U2. Select log in u 2. Login ; Joined.ToList (); //  

Here's another example when you calculate before joining:

  zero Enumerating_Then_Joining () {const string sc1 = @ "server = YOURSQLSERVER; Database = DEVDATABASE1; Trusted_Connection = true "; Const String sc2 = @" Server = YOURSQLSERVER; Database = DEVDATABASE2; Select the relational (true) = true; "; (Var DC = New data syntax (sc1)) (Select {var DC2 = New data syntax (sc2)} {var users1 = dc.getTable> User & gt; (). X = & gt; x) .Ollist (); //  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -