Bobby Bob
Bobby Bob
CC#
Created by Bobby Bob on 10/22/2022 in #help
Entity Framework SQL Error 19 - Foreign Key Constraint Failed
I've described the problem in significant detail here: https://stackoverflow.com/questions/74162855/entity-framework-sql-error-19-foreign-key-constraint-failed Not sure why I am getting the error I am getting. If you guys want to replicate the error, you should change the connection string Data Source = to your respective path of where the database CoffeeShop.db is in
3 replies
CC#
Created by Bobby Bob on 10/21/2022 in #help
Error 13 = Permission Denied [Answered]
3 replies
CC#
Created by Bobby Bob on 10/21/2022 in #help
Referencing a foreign key in a DBSet [Answered]
127 replies
CC#
Created by Bobby Bob on 10/19/2022 in #help
Not sure how to set up the model or entity for my code
5 replies
CC#
Created by Bobby Bob on 10/19/2022 in #help
(Concept Question) Delegates and Lambda Expressions [Answered]
I'm so confused about the concept of Delegates and Lambda Expression
namespace LINQ;

internal static class Program
{
static void Main()
{
var titanic = new Movie("Titanic", 1998, 4.5f);
PrettyPrint(titanic, (movie) => new string('*', (int)movie.Rating)); // "Lambda Expression"
}

private static void PrettyPrint(Movie movie, Func<Movie, string> printRating)
{
// var rating = printRating.Invoke(movie);
// Or simply
var rating = printRating(movie);

Console.WriteLine($"Name: {movie.Name}, Rating: [{rating}]");
}

// Note: This is "expression body"
private static int RandomMethod() => 20;
}

class Movie
{
public Movie(string name, int releaseYear, float rating)
{
Name = name;
ReleaseYear = releaseYear;
Rating = rating;
}

public string Name { get; set; }

public int ReleaseYear { get; set; }

public float Rating { get; set; }
}
namespace LINQ;

internal static class Program
{
static void Main()
{
var titanic = new Movie("Titanic", 1998, 4.5f);
PrettyPrint(titanic, (movie) => new string('*', (int)movie.Rating)); // "Lambda Expression"
}

private static void PrettyPrint(Movie movie, Func<Movie, string> printRating)
{
// var rating = printRating.Invoke(movie);
// Or simply
var rating = printRating(movie);

Console.WriteLine($"Name: {movie.Name}, Rating: [{rating}]");
}

// Note: This is "expression body"
private static int RandomMethod() => 20;
}

class Movie
{
public Movie(string name, int releaseYear, float rating)
{
Name = name;
ReleaseYear = releaseYear;
Rating = rating;
}

public string Name { get; set; }

public int ReleaseYear { get; set; }

public float Rating { get; set; }
}
Specifically this code (movie) => new string('*', (int)movie.Rating) Is this suppose to create a new method in place of (movie)? I looked through the lowered C# code on sharplab but it's even more confusing o-0
122 replies
CC#
Created by Bobby Bob on 10/18/2022 in #help
Unable to view exposed DataSet in Rider (EF Core 6.0) [Answered]
12 replies
CC#
Created by Bobby Bob on 10/17/2022 in #help
Error on trying to generate a MSSQLocalDB Database using EFCore on Rider [Answered]
85 replies
CC#
Created by Bobby Bob on 10/17/2022 in #help
How to access a type from a different project in the same solution? (Rider) [Answered]
13 replies
CC#
Created by Bobby Bob on 10/16/2022 in #help
Static vs Non-Static classes [Answered]
Please see here for the detailed question and all of the relevant code: https://gist.github.com/blueboy90780/f67813131e7a568d7998fcfea1166bd3
53 replies
CC#
Created by Bobby Bob on 10/14/2022 in #help
Can't access local variable inside an if...else statement [Answered]
115 replies
CC#
Created by Bobby Bob on 10/14/2022 in #help
IDE not recognizing property, unresolved symbol [Answered]
internal sealed class Menu //Displays the menu of food/drinks and prompting users for it
{
// When choosing option 1 (Adding to the order menu) the program will begin the prompt asking if adding a drink or a dessert
// Either drinksAvailable or dessertsAvailable will get instantiated but never both, one gets instantiated the other gets picked by garbage collection
static Dictionary<string, Dictionary<string, Tuple<int, int, int>>> drinksAvailable;
static Dictionary<string, Dictionary<string, int>> dessertsAvailable;
private string itemType { get; set; }

// Method to be invoked when user chooses option 1)
static Products TakeCustomerOrder()
{
Console.WriteLine("\n Select the type of product to add: \n 1) Drinks \n 2) Desserts");
int userChoice = Convert.ToInt32(Console.ReadLine());

// Instantiate drinks or dessert base on user input
if (userChoice == 1)
{
InstantiateDrinks();
ItemType = "drinks";
}
else if (userChoice == 2)
{
InstantiateDesserts();
ItemType = "desserts";
}
}
}
internal sealed class Menu //Displays the menu of food/drinks and prompting users for it
{
// When choosing option 1 (Adding to the order menu) the program will begin the prompt asking if adding a drink or a dessert
// Either drinksAvailable or dessertsAvailable will get instantiated but never both, one gets instantiated the other gets picked by garbage collection
static Dictionary<string, Dictionary<string, Tuple<int, int, int>>> drinksAvailable;
static Dictionary<string, Dictionary<string, int>> dessertsAvailable;
private string itemType { get; set; }

// Method to be invoked when user chooses option 1)
static Products TakeCustomerOrder()
{
Console.WriteLine("\n Select the type of product to add: \n 1) Drinks \n 2) Desserts");
int userChoice = Convert.ToInt32(Console.ReadLine());

// Instantiate drinks or dessert base on user input
if (userChoice == 1)
{
InstantiateDrinks();
ItemType = "drinks";
}
else if (userChoice == 2)
{
InstantiateDesserts();
ItemType = "desserts";
}
}
}
Why is that my IDE flags an error on ItemType = "drinks" and ItemType = "desserts"?
20 replies
CC#
Created by Bobby Bob on 10/14/2022 in #help
What is the difference between a dictionary and enum in C-Sharp? [Answered]
So I have the following enum
public enum FoodVariants
{
BananaCake = 29_000,
PassionFruitCheeseCake = 29_000,
CoffeeCheeseCake = 29_000,
TiramisuCake = 35_000,
PeachMousse = 35_000,
CocoaMousse = 35_000
}
public enum FoodVariants
{
BananaCake = 29_000,
PassionFruitCheeseCake = 29_000,
CoffeeCheeseCake = 29_000,
TiramisuCake = 35_000,
PeachMousse = 35_000,
CocoaMousse = 35_000
}
But I'm not sure if an enum is an appropriate type for this because I want to use a switch case statement with the enum based on the string input the program receives from console
17 replies
CC#
Created by Bobby Bob on 10/13/2022 in #help
Access Modifiers in C-Sharp [Answered]
Which access modifier take precedence during runtime? The access modifier at the class level, the method level or the field level? Do the access modifier at the class level override all the access modifier for it's members? Is there a precedence being taken place? etc... etc....
57 replies
CC#
Created by Bobby Bob on 10/12/2022 in #help
Difference between String and string keyword [Answered]
There's 2 string types that exists in C#. One with a capital letter and one without a capital letter. I've been taught, when I was learning Java, that by convention every primitive type is lowecase and every reference type is PascalCase. This convention seems to extend to C# as well. Every reference type in C# is CamelCase (+ properties, no idea if that's reference type or not). Everything adheres to this convention except for one which is the String keyword, I've no idea what the hell this is, why it exists and if it was even intended to be there in the language?
38 replies
CC#
Created by Bobby Bob on 10/10/2022 in #help
Confused about is-a relationship (static and dynamic types) [Answered]
C#
// Testing
BaseClass newObject = new BaseClass();
BaseClass newObjectB = new DerivedClass(209.21312f);
C#
// Testing
BaseClass newObject = new BaseClass();
BaseClass newObjectB = new DerivedClass(209.21312f);
What's with the syntax on the second line? And why would we ever use the syntax on the second line if it limits us to using only the members in DerivedClass? Like is
C#
BaseClass newObjectB = new DerivedClass(209.21312f);
C#
BaseClass newObjectB = new DerivedClass(209.21312f);
The same as
C#
BaseClass newObjectB = new BaseClass(209.21312f)
C#
BaseClass newObjectB = new BaseClass(209.21312f)
101 replies
CC#
Created by Bobby Bob on 9/24/2022 in #help
What is the SSH feature on most Jetbrain's IDE?
3 replies