|
satc wrote: In this case , I can't use a foreign key with the field ObjectID because it need
to be flexible ( related with different tables ) and I don't know if this is
possible. I'd recommend looking into 'normalization', a modelling technique for databases that helps a lot in these cases.
Add the table-name a a field to the event-table; the Id and tablename together would make each record unique. Since you don't want to repeat the table-name for each record, I'd suggest putting the table-name as a KeyPairValue (int/varchar) and link to that from the event-table.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy, I noticed you overlooked this part of his question - do you have a suggestion for that? (I don't)
Quote: But also , if I keep only the id , and add another field that keep the table name , how can I read with entity framework ? (Presumably as in "read the referenced record though it's not referenced by a foreign key")
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I don't see why it wouldn't be able to read it back.
In the worst case scenarion one would open an SqlConnection outside of EF, connect, read the id and tablename - and build a new command.
There's offcource no way to use a fieldname in the place of a table-name.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
SqlConnection outside EF - check.
But how could the non-worst case look like? (Maybe I'm having a stupid moment..)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: But how could the non-worst case look like? I don't have experience with EF; in the best case it would pick up the new column-name in the database, update the model and generate new entities. That would making reading the table easier for someone who is used to EF. To me, it is merely a select-statement.
The main problem here is getting the table-name (data) back into the sql-command. That is not something that can be done in Sql (unless you go to, spit, dynamic sql) and should be done in the codelayer above.
Make a new command, say "I need from table x the Id y" and of you are.
Sascha Lefèvre wrote: (Maybe I'm having a stupid moment..) Noes, you're not. I'm a bit more confused than usual, having trouble concentrating. Doesn't mean I'm not going to try
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Alright
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The problem is that as I know , the entity framework doesn't have a way to read where the entity name is variable :
Dim Ename as string
......
......
Dim query=From t in context.[Ename]..... select t
Can this work ?
|
|
|
|
|
No, that wont work.
There isn't really an EF way to do this. You'd need a switch and a separate function for each table type just to do the lookup and return the correct object type.
|
|
|
|
|
Alternatives:
- nullable references to every "regular" table in the event-table of which only one would be non-null
- a separate event-table for every "regular" table
edit: I realized I expressed this in terms of conventional, relational db design. In EF/ORM terms: You could have an abstract Event-entity and then derive concrete Event-entity-classes for each "regular" Entity.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 29-May-15 19:43pm.
|
|
|
|
|
Thank you for your alternatives.
But :
- If I create a FK for each table in the Event table , the event table will became very huge . Imagine 80-90 Fields only for these FK.
- If I keep a event table for each table then , will be more complicated :
Imagine 80-90 tables more on my database , and what about a query like this : " Display all the events in database on date 1/1/2015 " And after creating a report with these ???
Well , if these are the only solutions , I should choose ??!!
I'm curious which is the better way , because this problems about keeping an event table I think may be problems for other developers too.
|
|
|
|
|
Did you see my addition to my previous message? If you create an abstract Event-base-entity and derive concrete Event-entities for the "regular" tables from that, you can query all events, regardless to which table they belong.
The abstract Event-base-entity would hold all the information about the event, the derived concrete Event-entities only a reference to the record to which the event refers.
Query-examples:
DateTime dayOfInterest = new DateTime(2015, 1, 1);
var events = context.Events.Where(e => e.Date == dayOfInterest);
var allUserEvents = context.Events.OfType<UserEvent>();
Whether the concrete Event-entities end up in separate tables or in one table depends on which type of inheritance-mapping strategy you choose: Table per hierarchy (a single table for all events) or one of the other two (see http://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph[^]).
Regarding the creation of a report I have to completely pass.. but I can't imagine that the above idea would be a general problem for report creation.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
hello
can you help me about code to search global in datagriview
for exemple :
Dim dv As DataView
dv = New DataView(ds.Tables(0), "Département = EMBOU ", "", DataViewRowState.CurrentRows)
DataGridView1.DataSource = dv
but that not correct
|
|
|
|
|
|
Hello all,
Greetings for the day! I am working on a MOS Client , and i know all the stories in a rundown should have a unique ID, but i want to know whether we can have multiple story with same name inside one runorder. I read the MOS documentation thoroughly but can't figure it out. Any help will be highly appreciated. Thanks
Ankush Seth
|
|
|
|
|
Hi;
Does someone have an idea about creating a B2B procedure in vb6 or vba using the AS2 protocol to send and receive xml files.
I highly appreciate your help because I need it To upgrade my Access database.
Thanks.
|
|
|
|
|
As VB6 has not been support for many years it seems unlikely you are going to get much support for this.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
Does the vb.net 2013 has any possibility to compress a file with password protection ? I mean a built in feature without external tool ?
if , yes how can I do ?
Thank you !
|
|
|
|
|
That's depends on exactly what you're talking about.
No, VB.NET and the .NET Framework do not have anything built in to do this. YOU have to write the code to do it.
Now, in precise terms, what do you mean by "encrypt a file with a password"? Sure you can do that. Just pick an encryption algorithm and write an app that can accept a password and a source file, do the encryption using the password as a key or and/or salt and output an encrypted file.
Obviously, the app would also need to do the reverse.
Now, what exactly are you doing with the encrypted file and what do you hope to prevent?
|
|
|
|
|
No encrypt , just compress ( like .zip file) , but with a password to extract.
|
|
|
|
|
The .NET Framework ZIP file support doesn't support password protected Zip files.
You have to either write that kind of support yourself or use an external library, like DotNetZip[^].
|
|
|
|
|
I've seen the use of the CodeModule class to get the module code and procedure list from a project's modules. I've also seen the Find command to locate text.
However, I haven't found a way to jump to a particular line of code without changing it. The Find command doesn't seem to move the cursor.
Are there any examples of how to do this?
Ideally, I'd like to learn how to create a pane to list items that would allow a user to click and jump to code in a module.
Thanks.
|
|
|
|
|
You want to write an extension for an IDE that came out 17 years ago??
You're not going to find much more information than this[^].
There are examples out there. You just have to Google for "Visual Studio 6 add-in".
|
|
|
|
|
Hello !
Is there a way to detect if a file is a Word or Excel file regardless of the extension ?
I mean a file may be a Word file but has no extension ( by mistake ) , and also a file may have the .docx extension ( by mistake ) but it's not a true Word file.
What can I do ?
Thank you !
|
|
|
|
|
Some files contain identifiers at the beginning, but there is no guarantee that the file will be what you expect.
|
|
|
|
|
There is no 100% effective way to do this, other than opening trying to open the file in Word or Excel.
You can open the file using the normal file operations and look at the file header but you'll have to compare the header to the known headers of each file type you want to support.
But, that in no way means that you're really looking at a Word or Excel file.
|
|
|
|