Issue regarding fetching data from DB using LINQ and .NET [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Actually I don't have the idea that whether I should use some technique in storing data so that I can fetch according to my requirement or just need to search a query returning data according to my requirement. I want to store some data that is linked with eachother some rough data is given below
Name Reference City
Mian Null GUj
Hamza Mian Khi
Adam Mian Lhr
Jamil Adam Lhr
Musa Jamil Khi
Subhan Musa ISL
I want the solution that when I enter some name its fetches data of that person and its all childs and sub childs.
Ex:
If I enter Adam acoording to above table info it should return Adam, Jamil, Musa, Subhan.

Well you must have a foreign key for the parent.
Here is an example
select * from person parent
left join person child on child.Parent_ID = parent.ID
where parent.Name like 'Adam'
I think this should work for you, you could also left join the sub children of the sub children.
Or you can write query that search recursive.
Please see this article for more info
recursive-select

Related

Generate sequential number based on selected sequence [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a website dropdown that is populated from a SQL query. The values in the dropdown are from a table column and are like:
ABC-0123
ABC-0124
ABC-0125
ABC-0126.01
ABC-0126.02
ABC-0127
DEF-0123
DEF-0124
DEF-0125.1.01
DEF-0125.1.02
DEF-0125.2
I have a button to generate a new number based on what is selected in the dropdown. For example, if ABC-0125 is selected, ABC-0128 would need to be created since it's the next number in sequence. If ABC-0126.01 is selected, ABC-0126.03 would need to be created.
I'm looking for ideas on how to perform this. I considered just using the dropdown or querying the database directly.
I've split the selected value as a start:
String strDocFamily = drpDocFamily.SelectedValue;
string[] strDocTiers = strDocFamily.Split('.');
This may be open ended, but I'm looking for some suggestions on how to proceed. Thank you.
A solution might be to split the storage of the data into two or more columns, one for the alphabetic part ('ABC') another for the 'family' (0128 - the first set of digits) and others for the other tiers. You could then directly look up the maximum value of the 'family' column based on alphabetic. For example:
SELECT MAX(family-number)
FROM table-name
WHERE alpha-part='ABC';
Here is a UniqueID generator that can be easily adapted to generate a similar sequence to the one you need.
https://stackoverflow.com/a/39312025/2495728

C# how to get diagram name of element - Enterprise Architect [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need to get diagram`s name of specific elements. Is it possible ?
I added elements note with specific stereotypu using profile to EA project. Then i want create a plugin where i find this notes and diagram names where they are located. (i want export notes and diagram names to excel)....PS: Sorry for my bad english
Issue a SQL like
Repository.SQLQuery("SELECT t_diagram.name FROM t_diagramobjects AS dobj INNER JOIN t_diagram ON dobj.diagram_id = t_diagram.diagram_id WHERE t_diagramobjects.Object_ID = <elementID>"
Just replace <elementID> with the element's elementID. You could alternatively retrieve the diagram GUID (t_diagram.ea_guid') and get the diagram details viaRepostory.GetDiagramByGUID`.

Entity Framework - Assign parent object to object [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Let's suppose we have 2 tables:
Person
ID
Name
Nationality_ID (FK)
Nationality
ID
Name
With EF, in what contexts does it make sense and is correct to use each of the options below to add a nationality to a person? What is the different between them? What is the faster and the slower?
Option 1:
TheNationality.persons.Add(ThePerson);
Option 2:
ThePerson.nationality_id = TheNationality.id;
Option 3:
ThePerson.nationality = TheNationality;
If Person is the root of your aggregate and the focus of your application, most likely option 2 and option 3 make sense. Of those, option 3 is the more useful if you need to do additional domain logic based upon information in your nationality. Option 1 makes sense if the focus of your application is about nationality.
None of these methods is mutually exclusive. If you query and manipulate the objects from both perspectives, you can use options 1/3 or 1/2.
The resulting insert/update would be the same in all cases. Unless it is necessary to get TheNationality entity for some other reason, you could skip the read to obtain that and just assign the ID if you have it:
ThePerson.nationality_id = someNationalityIDVariable;

Structure for shop (e-commerce) database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I write my project and I will give to user to add his store to my system and then user will can to add shopItem to his store.
My question is:
Maybe already exist shop database for Category-Subcategory.
I mean - When user will add for example boots - he need choose
Category Clothes -> then choose Subcategory Shoes.
So i need database with all category-subcategory for MS SQL - or other database (maximum I will write script for transfer data to MS SQL)
Thank you.
Regards,
David.
You are talking about a hierarchical relationship. Typically you would have a Category database which has a primary key (say, CategoryID). If a subcategory can only belong to single category, then you would have another field in your Category table (maybe called ParentCategoryID). For root-level categories, this field would be NULL. For a subcategory, ParentCategoryID would contain the CategoryID of whatever category is the parent (pretty logical).
If a subcategory can exist under multiple categories, then you need a mapping table that contains the CategoryID and ParentCategory ID.
If you need a subcategory also to be allowed to be a root category, then your mapping table has to take this into account (maybe by allowing NULLs in the ParentCategoryID table)
MSDN has a tutorial on hierarchical data structures here: https://msdn.microsoft.com/en-us/library/bb677213.aspx

Mysql and c# updating [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I currently have a mysql data table that fills up when people complete a form. I then have my visual studio c# bot pull this data and do what I want. The table numbers the table using integers that increase by 1 each time. My bot looks in the table for id 1 and adds it.
The problem I have is that once my bot completes what someone wants and deletes the data, it does not recognize to go onto the next one since that id is not 1 and something else, like 2. I tried to have my c# bot add 1 to a variable each time and then have that variable represent the id so that every time the bot completed something it would go onto the next id. The problem with this was that every time the bot completed with one person the variable was reset back to 1. I am stuck now and can't figure out what to do. Any help would be great.
This is currently the string I use "select name from names where id = 1". If I can somehow instead of having the id = 1 and have it look for the next lowest id in my table then that would work.
Edit: Actually I think I figured out how to have the last added id be used. I will post it if I find it.
In MySQL, if you want the lowest ID then you could do something like this:
SELECT
Name
FROM
Names
ORDER BY ID
Limit 1
Is that what you are looking for?

Categories