Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microservices.LibCore.Core;
- using Microservices.LibCore.Core.Base.Models;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
- using NLog;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- public static List<object> setLegacyKey(DbContext dbContext, ServiceObject obj)
- {
- var keyValuesFound = new List<object>();
- var keyProperties = getKeyProperties(obj);
- foreach (var key in keyProperties)
- {
- string sql = "select " + getKeyColumnName(key) + " from " + getTableName(obj) + " where global_id=@p0"; //todo: while the risk is low, add some validation to prevent SQL injection
- List<object> result = dbContext.Database.SqlQuery(key.PropertyType, sql, obj.Id).ToListAsync().Result;
- if (result.Count == 0)
- {
- throw new ServiceException(ServiceError.ERROR_CODE.INVALID_REQUEST, String.Format("Invalid {1}.ID ({0})", obj.Id, obj.GetType().Name));
- }
- var keyValue = result.FirstOrDefault();
- key.SetValue(obj, keyValue);
- keyValuesFound.Add(keyValue);
- }
- return keyValuesFound;
- }
Add Comment
Please, Sign In to add comment