当前位置: 首页>>代码示例>>C#>>正文


C# IRepository.Insert方法代码示例

本文整理汇总了C#中IRepository.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.Insert方法的具体用法?C# IRepository.Insert怎么用?C# IRepository.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRepository的用法示例。


在下文中一共展示了IRepository.Insert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Seed

        public static void Seed(IRepository<Hub> hubRepository, IRepository<Channel> channelRepository, IRepository<ChatMessage> messageRepository)
        {
            hubRepository.Insert(new Hub("scottlogic", "Scott Logic", new List<Channel>()));

            channelRepository.Insert(new Channel("bristol", "scottlogic", "Bristol", DateTime.Now));
            channelRepository.Insert(new Channel("edinburgh", "scottlogic", "Edinburgh", DateTime.Now));
            channelRepository.Insert(new Channel("newcastle", "scottlogic", "Newcastle", DateTime.Now));

            messageRepository.Insert(new ChatMessage("nico", "bristol", "Bristol message", DateTime.Now));
            messageRepository.Insert(new ChatMessage("nico", "edinburgh", "Edinburgh message", DateTime.Now));
            messageRepository.Insert(new ChatMessage("nico", "newcastle", "Newcastle message", DateTime.Now));
        }
开发者ID:Stavrakakis,项目名称:Pickle,代码行数:12,代码来源:InMemoryDataSeeder.cs

示例2: MemoryRepositorySimpleTests

        public MemoryRepositorySimpleTests()
        {
            _database = new MemoryDatabase();
            var databaseProvider = Substitute.For<IMemoryDatabaseProvider>();
            databaseProvider.Database.Returns(_database);

            _repository = new MemoryRepository<TestEntity>(databaseProvider);

            // Testing Insert by creating initial data
            _repository.Insert(new TestEntity("test1"));
            _repository.Insert(new TestEntity("test2"));
            _database.Set<TestEntity>().Count.ShouldBe(2);
        }
开发者ID:lizhi5753186,项目名称:BDF,代码行数:13,代码来源:MemoryRepositorySimpleTests.cs

示例3: MemoryRepository_Simple_Tests

        public MemoryRepository_Simple_Tests()
        {
            _database = new MemoryDatabase();

            var databaseProvider = Substitute.For<IMemoryDatabaseProvider<int, long>>();
            databaseProvider.Database.Returns(_database);

            _repository = new MemoryRepository<MyEntity, int, long>(databaseProvider);

            //Testing Insert by creating initial data
            _repository.Insert(new MyEntity("test-1"));
            _repository.Insert(new MyEntity("test-2"));
            _database.Set<MyEntity>().Count.ShouldBe(2);
        }
开发者ID:andyshao,项目名称:ABP-1,代码行数:14,代码来源:MemoryRepository_Simple_Tests.cs

示例4: Seed

        public static async Task Seed(IRepository<Hub> hubRepository, IRepository<Channel> channelRepository, IRepository<ChatMessage> messageRepository)
        {
            var bristol = new Channel("bristol", "scottlogic", "Bristol", DateTime.Now);
            var edinburgh = new Channel("edinburgh", "scottlogic", "Edinburgh", DateTime.Now);
            var newcastle = new Channel("newcastle", "scottlogic", "Newcastle", DateTime.Now);

            await channelRepository.Insert(bristol);
            await channelRepository.Insert(edinburgh);
            await channelRepository.Insert(newcastle);

            var scottlogic = new Hub("scottlogic", "Scott Logic", new List<Channel>() {
                bristol,
                edinburgh,
                newcastle
            });
            
            await hubRepository.Insert(scottlogic);
        }
开发者ID:Stavrakakis,项目名称:Pickle,代码行数:18,代码来源:EntityFrameworkSeeder.cs

示例5: CreateNewTags

        /// <summary>
        /// The create new tags.
        /// </summary>
        /// <param name="tags">
        /// The tags.
        /// </param>
        /// <param name="tagRepository">
        /// The tag repository.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        private IList<Tag> CreateNewTags(IList<Tag> tags, IRepository<Tag, int> tagRepository)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }

            IList<Tag> result = new List<Tag>(tags.Count);
            for (int i = 0; i < tags.Count; ++i)
            {
                string content = tags[i].Content;
                Tag temp =
                    tagRepository.Query()
                                 .Filter(p => p.Content.Equals(content, StringComparison.Ordinal))
                                 .Get()
                                 .FirstOrDefault();
                if (temp == null)
                {
                    tagRepository.Insert(tags[i]);
                    result.Add(tags[i]);
                }
                else
                {
                    result.Add(temp);
                }
            }

            return result;
        }
开发者ID:RamanBut-Husaim,项目名称:TermWork-SignalRChat,代码行数:43,代码来源:ImageAlbumService.cs

示例6: GetProfile

        private Profile GetProfile(string username, bool isAnonymous, IRepository<Profile> profiles)
        {
            var profile = profiles
                .FirstOrDefault(p =>
                          p.User.UserName == username
                          && p.ApplicationName == ApplicationName
                          && p.IsAnonymous == isAnonymous);

            if (profile == null)
            {
                var membershipUser = UnitOfWork.Current.CreateRepository<User>()
                    .FirstOrDefault(p => p.UserName == username
                    && p.ApplicationName == ApplicationName);

                if (membershipUser == null)
                    throw new ProviderException("Profile cannot be created. There is no membership user");

                profile = new Profile();
                profile.IsAnonymous = isAnonymous;
                profile.LastUpdatedDate = System.DateTime.Now;
                profile.LastActivityDate = System.DateTime.Now;
                profile.ApplicationName = this.ApplicationName;
                profile.UserId = membershipUser.Id;

                profiles.Insert(profile);
            }
            return profile;
        }
开发者ID:netcasewqs,项目名称:elinq-membership,代码行数:28,代码来源:ELProfileProvider.cs

示例7: HomeViewModel

        public HomeViewModel(ILog log, IAccount account, ILocalize localize, IApplication application, IHistory history,
                             INavigationService navigationService, IUser user, IRepository repository,
                             IList<IExerciseType> exerciseTypes, ISettings settings)
        {
            _log = log;
            _localize = localize;
            _application = application;
            Account = account;

            _history = history;
            _history.OnHistoryItemsChanged += _history_OnHistoryItemsChanged;
            _NavigationService = navigationService;
            User = user;
            ExerciseTypes = exerciseTypes;
            _repository = repository;
            _settings = settings;
            _settings.OnSettingsChanged += _settings_OnSettingsChanged;
            _settings.Load();
            _history.Load();

            _repository.Single<User>(1).ContinueWith(t =>
                {
                    var foundUser = t.Result;
                    if (foundUser == null)
                    {
                        //this is first load of the app, set it up
                        _repository.Insert<User>(this.User).ContinueWith(task =>
                            {
                                this.User = this.User;
                                Account.AccessToken = this.User.RunkeeperToken;

                            });
                    }
                    else
                    {
                        User = foundUser;
                        Account.AccessToken = foundUser.RunkeeperToken;
                    }
                });

            if (_exerciseTypes == null || _exerciseTypes.Count == 0 ||
                (_exerciseTypes.Count == 1 && _exerciseTypes[0].Id == 0))
            {
                if (HomeViewModel.cachedTypes != null)
                {
                    this.ExerciseTypes = HomeViewModel.cachedTypes;
                    _log.Info("cache hit");
                }
                else
                {
                    _log.Info("cache miss");
                    this.ExerciseTypes = DefaultTypes;
                    _log.Info("default types set, querying");
                    _repository.Query<ExerciseType>("select * from ExerciseType").ContinueWith(t =>
                        {
                            _log.Info("query complete");
                            var types = t.Result;
                            if (types == null || types.Count == 0)
                            {

                                _log.Info("db does not have Exercise types, loading default items");
                                foreach (var e in from tt in this.ExerciseTypes orderby tt.Id select tt)
                                {
                                    _repository.Insert<ExerciseType>(e);
                                }
                            }
                            else
                            {
                                _log.Info("all excecise types retreived from the db, update local data store");
                                this.ExerciseTypes = (from tt in types select tt).ToArray();
                            }
                            _log.Info("cache extypes to static var");
                            HomeViewModel.cachedTypes = ExerciseTypes;

                        });
                }
            }
        }
开发者ID:nothingmn,项目名称:WindowsPhone.Common,代码行数:78,代码来源:HomeViewModel.cs

示例8: SeedData

        internal static void SeedData(IRepository repository)
        {
            Console.WriteLine("Seeding data...");

            // Seed Persons
            var persons = new List<Person>
                              {
                                  new Person {FirstName = "Arthur", LastName = "Smith", Gender = "M"},
                                  new Person {FirstName = "Bert", LastName = "Jones", Gender = "M"},
                                  new Person {FirstName = "Charlie", LastName = "Robertson", Gender = "M"}
                              };

            persons.ForEach(p => repository.Insert(p));

            // Seed Regions
            var regions = new List<Region>
                              {
                                  new Region {Name = "Banff National Park - South", Description = "Banff National Park"},
                                  new Region {Name = "Jasper National Park"},
                                  new Region {Name = "Kootenay National Park"},
                                  new Region {Name = "Banff National Park - North"},
                                  new Region {Name = "Kananaskis Country"}
                              };
            regions.ForEach(r => repository.Insert(r));

            // Seed Locations
            var locations = new List<Location>
                                {
                                    new Location
                                        {
                                            Name = "Bow Valley Parkway",
                                            Description = "Road from Banff to Lake Louise",
                                            Directions = "Turn left off main highway 2km north of Banff",
                                            Region = regions[0]
                                        },
                                    new Location {Name = "Banff Townsite area", Region = regions[0]},
                                    new Location
                                        {
                                            Name = "Bow Lake area",
                                            Description = "20 minutes north of Lake Louise on IceField Parkway",
                                            Region = regions[3]
                                        },
                                    new Location {Name = "Smith Dorrien Highway", Region = regions[4]}
                                };
            locations.ForEach(l => repository.Insert(l));

            // Seed Difficulty Levels
            var difficulties = new List<Difficulty>
                                   {
                                       new Difficulty {DifficultyType = "Easy"},
                                       new Difficulty {DifficultyType = "Moderate"},
                                       new Difficulty {DifficultyType = "Challenging"},
                                       new Difficulty {DifficultyType = "Difficult"}
                                   };
            difficulties.ForEach(d => repository.Insert(d));

            // Seed TrailType Levels
            var trailTypes = new List<TrailType>
                                 {
                                     new TrailType {TrailTypeName = "Land"},
                                     new TrailType {TrailTypeName = "Air"},
                                     new TrailType {TrailTypeName = "Water"}
                                 };
            trailTypes.ForEach(t => repository.Insert(t));

            // Seed TransportType Levels
            var transportTypes = new List<TransportType>
                                     {
                                         new TransportType {TransportTypeName = "Hike"},
                                         new TransportType {TransportTypeName = "Cycle"},
                                         new TransportType {TransportTypeName = "Canoe"},
                                         new TransportType {TransportTypeName = "Ski"},
                                         new TransportType {TransportTypeName = "Snowshoe"},
                                         new TransportType {TransportTypeName = "Aeroplane"}
                                     };
            transportTypes.ForEach(t => repository.Insert(t));

            // Seed Trails
            var trails = new List<Trail>
                             {
                                 new Trail
                                     {
                                         Name = "Johnstone Canyon",
                                         Description = "Johnstone Canyon",
                                         Distance = 4.8M,
                                         ElevationGain = 200,
                                         EstimatedTime = 2,
                                         Location = locations[0],
                                         TrailType = trailTypes[0],
                                         Difficulty = difficulties[0],
                                         ReturnOnEffort = 9.2M,
                                         OverallGrade = 7.2M,
                                         Notes =
                                             "Good Waterfalls scenery. Good in all seasons. Take crampons in winter/spring",
                                         Longitude = -102,
                                         Latitude = 50
                                     },
                                 new Trail
                                     {
                                         Name = "Burstall Pass",
//.........这里部分代码省略.........
开发者ID:andy-thomas,项目名称:Trails2010,代码行数:101,代码来源:Util.cs

示例9: AddOrUpdateSetting

        private static bool AddOrUpdateSetting(IRepository<SettingData> repository, SettingKey key, IProxyType<string> value)
        {
            SettingData setting = repository.Query.FirstOrDefault(_ => _.Identifier == key.Identifier && _.Name == key.Name);

            if (setting == null)
            {
                setting = new SettingData();
                setting.Identifier = key.Identifier;
                setting.Name = key.Name;

                repository.Insert(setting);
            }

            string valueToPersist = value.ProxiedValue;
            if (!string.Equals(setting.Value, valueToPersist, StringComparison.Ordinal))
            {
                setting.Value = valueToPersist;

                return true;
            }

            return false;
        }
开发者ID:Giecha,项目名称:AlarmWorkflow,代码行数:23,代码来源:SettingsServiceInternal.cs


注:本文中的IRepository.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。