EntityRepository.Insert C# (CSharp) Method

Insert() public method

public Insert ( Entity entity ) : Entity
entity Entity
return Entity
        public Entity Insert(Entity entity)
        {
            // TODO: Insert entity into database here
        }
    

Usage Example

Esempio n. 1
0
        public void TestAddPosts()
        {
            var dbFactory = new OrmLiteConnectionFactory(
                System.Configuration.ConfigurationManager.ConnectionStrings["Test"].ConnectionString,
                PostgreSqlDialect.Provider);

            var postRepository = new EntityRepository <Post>(dbFactory);
            var random         = new Random();

            var ids = new List <long>();

            ids.Add(postRepository.Insert(new Post()
            {
                Message  = $@"TEST MESSAGE {random.Next()}",
                UserId   = 1,
                ParentId = 1
            }));

            for (int i = 0; i < 10; ++i)
            {
                var pId = ids[random.Next(0, ids.Count)];

                var postStart = random.Next(TestData.BaconIpsum.Length - 30);
                var length    = random.Next(TestData.BaconIpsum.Length - postStart);
                ids.Add(postRepository.Insert(new Post()
                {
                    Message  = $@"TEST MESSAGE Parent: {pId}, Text: {TestData.BaconIpsum.Substring(postStart, length)}",
                    UserId   = 1,
                    ParentId = pId
                }));
            }
        }
All Usage Examples Of EntityRepository::Insert