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


C# Db.SaveChangesAsync方法代码示例

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


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

示例1: Save

        public async Task<int> Save(long routeId, long stationId, int number)
        {
            if(routeId <= 0) throw new ArgumentException("routedId <= 0");
            if(stationId <= 0) throw new ArgumentException("stationId <= 0");

            using (var db = new Db())
            {
                using (var transtaction = db.Database.BeginTransaction(IsolationLevel.RepeatableRead))
                {
                    try
                    {
                        var route = db.Routes.SingleOrDefault(r => r.Id == routeId);
                        if (route == null) throw new NullReferenceException("route");

                        var station = db.Stations.SingleOrDefault(r => r.Id == stationId);
                        if (station == null) throw new NullReferenceException("station");

                        var routeStation = new RouteStation() { Number = number, RouteId = routeId, StationId = stationId };
                        db.Entry(routeStation).State = EntityState.Added;
                        return await db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message);
                        transtaction.Rollback();
                        throw;
                    }
                }
            }

        }
开发者ID:Dorskiy,项目名称:RouterWebAppSharp,代码行数:31,代码来源:IRouteStationRepository.cs

示例2: Update

        public async Task Update(Color t)
        {
            
            if (t == null)
                throw new NullReferenceException("color");

            using (var db = new Db())
            {
                db.Entry(t).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
        }
开发者ID:Dorskiy,项目名称:RouterWebAppSharp,代码行数:12,代码来源:ColorRepository.cs

示例3: Save

        public async Task Save(Color t)
        {
            if(t == null)
                throw new NullReferenceException("color");

            using (var db = new Db())
            {
                try
                {
                    db.Entry(t).State = EntityState.Added;
                    await db.SaveChangesAsync();
                }
                catch (Exception exception)
                {
                    Log.Error(exception.Message);
                    throw;
                }
            }
        }
开发者ID:Dorskiy,项目名称:RouterWebAppSharp,代码行数:19,代码来源:ColorRepository.cs

示例4: Delete

        public async Task<int> Delete(long routeId, Station station)
        {
            if(routeId <= 0) throw new ArgumentException("routeId <= 0");
            if(station == null) throw new ArgumentNullException("station");

            using (var db = new Db())
            {
                try
                {
                    if (station.Id <= 0)
                    {
                        station = await _stationRepository.GetByLatLng(station.Latitude, station.Longitude);
                        if(station == null)throw new NullReferenceException("station");
                    }

                    var routeStation = new RouteStation() {RouteId = routeId, StationId = station.Id};
                    db.Entry(routeStation).State = EntityState.Deleted;
                    return await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message);
                    throw;
                }
            }

        }
开发者ID:Dorskiy,项目名称:RouterWebAppSharp,代码行数:27,代码来源:IRouteStationRepository.cs


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