Click here to Skip to main content
15,886,518 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: StringBuilder error Pin
samflex5-Jul-23 15:43
samflex5-Jul-23 15:43 
QuestionPremature return to Index.razor Pin
TNCaver1-Jun-23 10:27
TNCaver1-Jun-23 10:27 
AnswerRe: Premature return to Index.razor Pin
TNCaver16-Jun-23 6:17
TNCaver16-Jun-23 6:17 
QuestionEnable to read the DIO values its getting error on page Pin
Member 1601716729-May-23 16:17
Member 1601716729-May-23 16:17 
AnswerRe: Enable to read the DIO values its getting error on page Pin
jschell30-May-23 5:24
jschell30-May-23 5:24 
QuestionRazor RadioButton ViewModel Property Binding Pin
j11codep25-May-23 16:54
j11codep25-May-23 16:54 
AnswerRe: Razor RadioButton ViewModel Property Binding Pin
Richard Deeming25-May-23 21:37
mveRichard Deeming25-May-23 21:37 
Question.Net Core 6 - IMongoCollection, Suppression State Warning CS8602 Dereference of a possibly null reference. Pin
jkirkerx16-May-23 17:56
professionaljkirkerx16-May-23 17:56 
Been some years now since I worked with .Net Core 3, been busy with PHP 8, and was surprised at the new stuff in .Net Core 6, and it's insatiable appetite to point out null conditions, so I'm playing along with it for now. But I just can't wrap my head around this one, and I'm starring at it like a deer in the headlights. So I asked VS 2022 for suggestions, and it suggested converting my old code to these new statements. I read the documentation .. Resolve nullable warnings | Microsoft Learn and I didn't see any anything that sort of matched what I'm doing here. I tried ...

Right hand side ?? "_database maybe null" but it said that it can't be applied to operands of type IMongoCollection<account> and strings.

Perhaps someone else has run into this and can give me a pointer or a solid. But I'll keep researching this to see if I can find something.

My old code example from .Net Core 3
C#
<br />
public IMongoCollection<ACCOUNTS> Accounts
{
    get { return _database.GetCollection<ACCOUNTS>("Accounts"); }
}<br />

My new code that VS 2022 Suggested
C#
internal class MongoDbContext : IDisposable
{
    private IMongoDatabase? _database;

<pre>
public void MongoDBContext()
{

    // Grab the MongoDB Connection and Database
    var rootObject = AppSettingsJson.GetSettings();
    var dbConnection = rootObject?.Settings?.DbConnection;
    var connString = "mongodb://" + dbConnection?.User + ":" + dbConnection?.Pass + "@" + dbConnection?.Host;
    var client = new MongoClient(connString);
    _database = client.GetDatabase(dbConnection?.Database);

}

// MongoDB Database Models        
// I don't understand how to perform a null check, or to satisfy the compiler for "_database" - _database may be null here CS8602
public IMongoCollection<ACCOUNTS> Accounts => _database.GetCollection<ACCOUNTS>("Accounts");
public IMongoCollection<SHIPPERS> Shippers => _database.GetCollection<SHIPPERS>("Shippers");
public IMongoCollection<CONTACTS> Contacts => _database.GetCollection<CONTACTS>("Contacts");
public IMongoCollection<PALLETS> Pallets => _database.GetCollection<PALLETS>("Pallets");
public IMongoCollection<CUSTOMERS> Customers => _database.GetCollection<CUSTOMERS>("Customers");
public IMongoCollection<BILLOFLADING> BillOfLading => _database.GetCollection<BILLOFLADING>("BillOfLading");
public IMongoCollection<SHIPPINGADDRESSES> ShippingAddresses => _database.GetCollection<SHIPPINGADDRESSES>("ShippingAddresses");

public IMongoCollection<countries> Countries => _database.GetCollection<countries>("Countries");

}

If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerI think I got it Pin
jkirkerx16-May-23 19:22
professionaljkirkerx16-May-23 19:22 
GeneralRe: I think I got it Pin
Graeme_Grant16-May-23 21:35
mvaGraeme_Grant16-May-23 21:35 
GeneralRe: I think I got it Pin
jkirkerx17-May-23 6:36
professionaljkirkerx17-May-23 6:36 
QuestionHttpUtility.UrlEncode in vb.net Pin
muad AHMED dr3-May-23 20:56
muad AHMED dr3-May-23 20:56 
AnswerRe: HttpUtility.UrlEncode in vb.net Pin
Richard Deeming3-May-23 21:59
mveRichard Deeming3-May-23 21:59 
QuestionVB Linq - Group invoices by store, and include all the invoice items Pin
jkirkerx19-Apr-23 9:20
professionaljkirkerx19-Apr-23 9:20 
AnswerRe: VB Linq - Group invoices by store, and recalculate margin Pin
jkirkerx19-Apr-23 10:00
professionaljkirkerx19-Apr-23 10:00 
QuestionLanguage specific UseRewriter i startup .net core 7 Pin
Tablet510-Apr-23 11:25
Tablet510-Apr-23 11:25 
AnswerRe: Language specific UseRewriter i startup .net core 7 Pin
Richard Deeming10-Apr-23 21:36
mveRichard Deeming10-Apr-23 21:36 
AnswerRe: Language specific UseRewriter i startup .net core 7 Pin
Richard Deeming11-Apr-23 2:20
mveRichard Deeming11-Apr-23 2:20 
QuestionWeird issue with input form on a simple ASP.NET core web application Pin
Maximilien22-Mar-23 6:49
Maximilien22-Mar-23 6:49 
AnswerRe: Weird issue with input form on a simple ASP.NET core web application Pin
Richard Deeming27-Mar-23 0:42
mveRichard Deeming27-Mar-23 0:42 
GeneralRe: Weird issue with input form on a simple ASP.NET core web application Pin
Maximilien27-Mar-23 6:12
Maximilien27-Mar-23 6:12 
QuestionMessage Removed Pin
19-Mar-23 17:21
samflex19-Mar-23 17:21 
QuestionNeed to Integrate Swipe Machine in my C# Application for billing Pin
Member 159385451-Mar-23 0:58
Member 159385451-Mar-23 0:58 
AnswerRe: Need to Integrate Swipe Machine in my C# Application for billing Pin
Richard Deeming1-Mar-23 1:07
mveRichard Deeming1-Mar-23 1:07 
AnswerRe: Need to Integrate Swipe Machine in my C# Application for billing Pin
jschell20-Mar-23 6:40
jschell20-Mar-23 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.