|
If you're talking about using the Data Sources tab in Visual Studio to connect to the database, and you're using Entity Framework, you're doing it wrong. The Visual Studio designers will not create classes for Entity Framework. You have to write the classes yourself.
|
|
|
|
|
If I connect the data base to Visual Studio and create my own classes, will Visual Studio connect my classes to the tables in the data base?
|
|
|
|
|
It appears you have no idea what Entity Framework is or how it works, correct?
Visual Studio isn't going to do anything for you when using Entity Framework, nor should you rely on it. Using the designers in Visual Studio hides a bunch of details from you that makes learning how to interact with databases more difficult to learn. You don't need anything from Visual Studio to work with databases.
|
|
|
|
|
Downloads: Generic Database Access[^]
This a HUGE Codeproject article which, from the looks of things (quick scroll through the .zip content), is likely to give out many C# programming secrets wrt SQL Server (even) with no further sacrifice of time searching on your part.
Generic Database Access[^]
|
|
|
|
|
I have a strange issue I am experiencing with a web app. Typically, the user right clicks on the web page and click Print. He views the document in preview and then decides how to print it.
On Chrome, everything works fine
On Microsoft Edge, It only works if you right click the web page at the top of the page. If you scroll down to the bottom of the page before you right click and select print, the printed document is not formatted properly. The print preview is also not formatted properly. See screen shots below:
On Chrome - (User right click from bottom of page)
You can see the title of the app, title of the report, report run date etc
Report Issue - Chrome.PNG - Google Drive[^]
On MS Edge - (User right click from bottom of page)
The preview starts at some random data as shown below. Title of the app, title of report etc are not shown in the preview and printed version.
Report Issue - MS Edge.PNG - Google Drive[^]
As you can see from the above screen shots, Chrome is displayed properly. MS Edge only displays like that if I right click on the web page from the top of the page without scrolling down
Below is my code sample:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Physician Activity Report</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link href="~/lib/font-awesome/css/all.css" rel="stylesheet" />
<link href="~/css/mycss.css" rel="stylesheet" media="print" />
</head>
Below is the content of mycss.css
@media print {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-12 {
width: 100%;
}
.col-md-11 {
width: 91.66666666666666%;
}
.col-md-10 {
width: 83.33333333333334%;
}
.col-md-9 {
width: 75%;
}
.col-md-8 {
width: 66.66666666666666%;
}
.col-md-7 {
width: 58.333333333333336%;
}
.col-md-6 {
width: 50%;
}
.col-md-5 {
width: 41.66666666666667%;
}
.col-md-4 {
width: 33.33333333333333%;
}
.col-md-3 {
width: 25%;
}
.col-md-2 {
width: 16.666666666666664%;
}
.col-md-1 {
width: 8.333333333333332%;
}
}
h5 {
color: darkblue;
}
What can I do to get this to work properly on MS Edge ? Is it a CSS issue ?
|
|
|
|
|
No idea what the answer is but I did upvote the question because someone down voted it and without explanation. Seems like a reasonable question to me.
Perhaps they wanted you to post in a different forum but didn't feel like explaining that.
|
|
|
|
|
Yeah. It is a strange issue that our users recently brought up. Most users use MS Edge. I don't know what angle to analyze from. It is a .NET Core web app.
|
|
|
|
|
I use Edge as a secondary browser when Firefox fails to display a dark background with light foreground because it (Edge) and it's settings remain at default. Nothing there in a contextual right-click and print (apparently CTrl+P also) fails when the target format is .PDF; so I suggest ... printing from the saved .pdf document instead of printing to .png.
|
|
|
|
|
Hi @RedDK, thanks for your input. Yeah CTrl+P also fails. Like I said in the question even the generated PDF is not formatted properly for MS Edge. Why is it that it works if I right click and click print from the top of the web page but as soon as I scroll down and do the same action it doesn't work in MS Edge ? What can I do to fix it ? What code do I need to add? Why don't I experience same issue in Chrome?
|
|
|
|
|
Perhaps your reticense to post actual code instead of showing images through links is what's keeping me from seeing what could possibly be wrong here. I can right-click and Print this as-is ... with no difficulties.
|
|
|
|
|
I found the answer:
It's a known issue in Edge version 126. The fix has been included in Stable 126.0.2592.81, which had been released on June 27, 2024. Please install the latest Edge Stable version 126.0.2592.81 (Official build) and test again.
|
|
|
|
|
Hello everyone,
I try to connect a pc to some esp32 arudino boards using tcp sockets
the idea is that on the each esp board I open a server that accapt the pc( client ) request and also a client that is used to do all data traffic between the pc and esp
the pc and the board use the some router as AP i wrote some thing like that using Jyhton
Now i want to do the some for other project but on the PC I run a VS2022 C# program that connect to the esp boards but i don't know how to do it .
Can someone show me the road ( an example will be great )
Regards Doron
|
|
|
|
|
You are going to have to give us a lot more detail than that - we have no idea what you have tired, where you are stuck, or what help you might need - if you have a working example, most developers should be able to alter it to fit the new circumstances, so we are at a loss to know what you expect from us that will help you get there.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi
May be is was not clear , I don't have code written yet.
i want to get the idea how to create and manage many client sockets on my pc so i can select the socket i will send the data to by using the ip or other index
Doron
|
|
|
|
|
Doesn't matter how you 'think' about the design the following is true.
For TCP sockets there is always a 'server' and a 'client'.
The 'server' creates a listener port and waits for a connection.
The 'client' opens a socket to the server. So the client is the one that initiates the connection.
After a connection is created either side can send and receive requests. Although often the client is the one that sends most requests.
The above also means that the server must have an addressable IP address. Probably in your situation that will not matter but it does mean you will need to figure out what the servers IP address is.
-----------------------------
Now for your actual code whether your want the pc or arudino to be the server is up to you. (I know very little about the second but I expect it can act as both a server and client.)
However I suggest that you start your learning experience using the PC only. So you will have two programs that run on your PC. One is the server. One is the client.
You can google for examples of writing code exactly like that in C#.
After you have tested that a bit then I suggest again only on the PC that you simulate what you want to actually do using the sample code. So for example if you want to send a specific command to the arudino then add code to do that in the PC code (client probably) and then respond in a pseudo way on the other side of the PC code.
You might also want to figure out how to analyze problems while you are developing this.
So for example you might do the following
- PC server code to simulate arudino
- Command received: Health check. Returns 'ok'
- PC client code to send command
- Command send: Health check
- Use Console.WriteLine() to write the command to send (all information)
- Use socket code to send it
- Use socket code to recieve response
- Use Console.WriteLine to write the response (all information.)
You should also experiment with what happens when the IP address is wrong and what happens if the server is not running.
-----------------------------------------------------------------------
As additional suggest for quite a bit in the future for a full application relying on Console.WriteLine() is not workable. So investigate 'logging'. You should not do this until you are comfortable with sockets.
|
|
|
|
|
|
Hello,
I have list checked box has items like "C:\" , "D:\" etc... and each item user can check or not. I need to test if current loop string value (drive) is checked or not in the list box
In addition I want to test "if not" condition for ex like this:
if (drive not in chklist_drives.CheckedItems) continue;
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?
That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hold on. I did not that my question is vague . I have a list checked box that has items like "C:\", "D:\" etc...
and I need to check current string value in a loop if that value is checked or not in the list box
What I tried:
I have a loop like this:
foreach (drive in all drives)
{
if (drive not in chklist_drives.CheckedItems) continue;
}
Thats it I dont know how I can implement this if line of code
|
|
|
|
|
As you have discovered, drive not in chklist_drives.CheckedItems is not valid C#.
Assuming this is a Windows Forms CheckedListBox control, the CheckedItems collection provides a Contains method to test whether an item is in the collection:
CheckedListBox.CheckedItemCollection.Contains(Object) Method (System.Windows.Forms) | Microsoft Learn[^]
But you're also going to find that foreach (drive in all drives) is not valid C# either. Perhaps you're looking for the System.IO.DriveInfo.GetDrives method[^]?
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (!drive.IsReady) continue;
if (!chklist_drives.CheckedItems.Contains(drive.Name)) continue;
...
} You'll need to adjust that code so that the value you check for in the list matches the value you added to the list in the first place.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks alot. Second if is what I need.
|
|
|
|
|
Now compare that against your original question and it should be obvious why it took you 8 hours to get an answer!
If you give us details we can help a lot quicker!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I'm currently learning how to use Entity Framework Core and I'm trying to create a "more advanced" application divided into multiple projects.
When I was using ADO.NET, I would usually make:
- Project.DatabaseAccess - for managing connection strings,
- Project.Shared - base classes and interfaces (which implement INotifyPropertyChanged)
- for example Project.Customers - models for customer-related stuff and a static class with CRUD methods for them.
Customers would then reference the Shared and DatabaseAccess projects.
When using EfCore, I wanted to achieve similar structure, so:
- Project.DatabaseAccess - managing connection strings, main DbContext
- Project.Shared,
- Project.Customers - models for customer-related stuff and repositories for them (with DbContext provided in the constructor)
The problem with that approach is that Customers reference to the DatabaseAccess (for accessing DbContext), and DatabaseAccess needs to reference to the Customers (because it has DbSet<customer>). Unfortunately, you can't make A<-->B references in the Visual Studio.
What other project structures do you recommend? I know that there is something called CleanArchitecture (Application, Domain, Infrastructure), but it doesn't provide the separation between different spheres of my program (Project.Customers, Project.Planning, Project.Mailing, etc.)
Thank you in advance!
|
|
|
|
|
nwbkn wrote: you can't make A<-->B references in the Visual Studio
You can use interfaces for circular references.
nwbkn wrote: Customers reference to the DatabaseAccess
Your Data API layer accepts DTOs (Data Transfer Object) and returns DTOs. So 'Customer' is a DTO which the CustomerDB class uses. Although you can choose your own names for the classes.
Create Data Transfer Objects (DTOs) | Microsoft Learn[^]
Be very careful about what you put in a DTO. Probably to start out you should have nothing but properties.
|
|
|
|
|