相关疑难解决方法(0)

多个添加的实体可以具有相同的主键

这是我的3个实体模型:Route,Location和LocationInRoute.
模型

以下方法失败并在提交时获取异常:

 public static Route InsertRouteIfNotExists(Guid companyId, IListLocation> locations)
        {
            //Loop on locations and insert it without commit
            InsertLocations(companyId, routesOrLocations);

            RouteRepository routeRep = new RouteRepository();
            Route route = routeRep.FindRoute(companyId, locations);
            if (route == null)
            {
                route = new Route()
                {
                    CompanyId = companyId,
                    IsDeleted = false
                };
                routeRep.Insert(route);
                LocationInRouteRepository locInRouteRep = new LocationInRouteRepository();
                for (int i = 0; i < locations.Count; i++)
                {
                    locInRouteRep.Insert(new LocationInRoute()
                    {
                        //Id = i,
                        LocationId = locations[i].Id,
                        Order = i,
                        RouteId = route.Id
                    });
                } …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

75
推荐指数
1
解决办法
5万
查看次数

标签 统计

.net ×1

c# ×1

entity-framework ×1