Tuesday, February 8, 2022

How to work with GrandNode2 and CURD to Mongo

 Sample Select



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
            //Get Connection String
            var connection = DataSettingsManager.LoadSettings();
            //Connect to database and get table referance 
            IRepository<Domain.Catalog.Product> _productRepository = new Domain.Data.Mongo.MongoRepository<Domain.Catalog.Product>(connection.ConnectionString);
            
            List<string> AllBundleProductsIds = new System.Collections.Generic.List<string>();
         
            //select from DB table
            var ProductDetails = _productRepository.Table.FirstOrDefault(x => x.Id == "62016cb9a84d6af2be24d0cc");
            if (ProductDetails != null && ProductDetails.BundleProducts.Any())
            {
                    foreach (var item in ProductDetails.BundleProducts)
                    {
                        AllBundleProductsIds.Add(item.ProductId);
                    }
            }
            


Insert New Record

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
            //Get Connection String
            var connection = DataSettingsManager.LoadSettings();
            //Connect to database and get table referance 
            IRepository<Picture> _pictureRepository  = new MongoRepository<Picture>(connection.ConnectionString);
            var picture = new Grand.Domain.Media.Picture
            {
                PictureBinary = File.ReadAllBytes("c:\\images\\logo.jpg"),
                MimeType = "image/jpeg",
                SeoFilename = "",
                AltAttribute = "",
                TitleAttribute = "",
                Reference = 0,
                ObjectId = "",
                IsNew = true,
            };

            _pictureRepository.Insert(picture);


Available Mongo-Linq commands

https://mongodb.github.io/mongo-csharp-driver/1.11/linq/

https://zetcode.com/csharp/mongodb/


 

No comments: