I have a SQL database with several tables which are linked together.
"Project" table: Contains informations about projects
"Release" table: Contains informations about releases which are related to projects (one project -> multiple releases; one release -> one project)
"IssuesSW" table: Contains informations about issues which are related to releases (one issueSW -> linked in multiple releases; one release -> contains multiple issuesSW)
In my first solution I just returned the full list of about 10.000 issues but for additional filtering options (based on the projects/releases the issues depends on) I need additional data from the projects and the releases.
The first solution I had took about 2 seconds until the request (and the drawing of some charts on the front end) finished but with the additional data I had to start on the project level and go down till I reach the issues and that takes much too long now.
In my current solution I just used foreach loops to go threw the projects and find their releases and then go threw the releases and find all the issues:
[HttpPost]
public JsonResult GetReleasesWithIsws()
{
using (var db = new SwMetricsContext())
{
var result = new List<GetCustomerReleasesWithIswsResult>();
var projects = db.Projects.ToList();
foreach (var project in projects)
{
var releases = db.PVERs.Where(x => x.Project_ID == project.ID).ToList();
foreach(var release in releases)
{
var pver_result = new GetCustomerReleasesWithIswsResult()
{
Project_Id = project.ID,
Project_Title = project.Title,
Project_Generation = project.Generation,
Project_DefaultDevelopmentMethod = project.DefaultDevelopmentMethod,
Release_Id = release.ID,
Release_Category = release.Category,
Release_Classification = release.Classification,
Release_Department = project.ResponsibleAtBosch,
Release_ImplementationFreeze = release.ImplementationFreeze,
Release_LifeCycleState = release.LifeCycleState,
Release_PlannedDate = release.PlannedDate,
Release_SpecificationFreeze = release.SpecificationFreeze,
Release_Title = release.Title,
Release_Type = release.Type
};
var isw_connections = db.PVERIssuesSW.Where(x => x.Release_ID == release.ID).ToList().Select(x => x.IssueSW_ID).ToHashSet();
var isws = db.IssuesSW.Where(x => isw_connections.Contains(x.ID)).ToList();
pver_result.Release_Isws.AddRange(isws);
result.Add(pver_result);
}
}
var json = Json(result);
json.MaxJsonLength = int.MaxValue;
return json;
}
}
But the problem with this solution is it takes much too long (about 30 seconds).
So if someone has a better solution for me I would be very thankful :)
Here are the 3 database table models:
[Table("DGSIT_SWMetrics_Projects")]
public class Project
{
public string ID { get; set; }
public string Title { get; set; }
public int Customer_ID { get; set; }
public string Responsible { get; set; }
public string DefaultDevelopmentMethod { get; set; }
public string Generation { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string SpjmName { get; set; }
}
[Table("DGSIT_SWMetrics_PVERs")]
public class Pver // Release
{
public string ID { get; set; }
public string Project_ID { get; set; }
public string Type { get; set; }
public string Title { get; set; }
public string PlannedDate { get; set; }
public string ImplementationFreeze { get; set; }
public string SpecificationFreeze { get; set; }
public string LifeCycleState { get; set; }
public string Category { get; set; }
public string Classification { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
[Table("DGSIT_SWMetrics_IssuesSW")]
public class IssueSW
{
public string Project_ID { get; set; }
public string ID { get; set; }
public string Title { get; set; }
public string LCS { get; set; }
public string Category { get; set; }
public string DevelopmentMethod { get; set; }
public string Allocation { get; set; }
public string Tags { get; set; }
public string SubmitDate { get; set; }
public string ExternalReview { get; set; }
public int Assignee_ID { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
IssueSW has itΒ΄s own "Project_ID" because it depends on one "Cluster-Project". But itΒ΄s also linked to the Releases with an extra table:
[Table("DGSIT_SWMetrics_PVERIssuesSW")]
public class PVERIssueSw
{
public int ID { get; set; }
public string Release_ID { get; set; }
public string IssueSW_ID { get; set; }
}
Related
I've been searching around for a long while for this, I haven't found any solutions to my issue which is:
I've been trying get a json data individually from a whole source seen here:
{"TargetId":0,"ProductType":null,"AssetId":1239281845,"ProductId":0,"Name":"β€οΈπππππβοΈπβ€οΈ Red&Black Flannel + Backpack","Description":"Shirt Image","AssetTypeId":1,"Creator":{"Id":124026176,"Name":"TheDestroyerPeter","CreatorType":"User","CreatorTargetId":124026176},"IconImageAssetId":0,"Created":"2017-12-12T19:48:24.693Z","Updated":"2017-12-12T19:48:24.693Z","PriceInRobux":null,"PriceInTickets":null,"Sales":0,"IsNew":false,"IsForSale":false,"IsPublicDomain":false,"IsLimited":false,"IsLimitedUnique":false,"Remaining":null,"MinimumMembershipLevel":0,"ContentRatingTypeId":0}
now what I've been trying to do with it is get the Product Name using C# and the product name is "β€οΈπππππβοΈπβ€οΈ Red&Black Flannel + Backpack", my issue is that I haven't found a way to extract the data, and when I have I haven't been able to get the right data, because instead if gives me "TheDestroyerPeter"
I've written up code, and deleted it, it was really sloppy and it would take awhile to rewrite, I appreciate any solutions
-whoever I am
You can use JavaScriptSerializer class, which is part of the System.Web.Script namespace.
For example :
var jsonString = #"{""name"":""John Doe"",""age"":20}";
var JSONObj = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(jsonString );
and then JSONObj["name"]; gives you "John Doe"
in this case you can use it :
public class Creator
{
public int Id { get; set; }
public string Name { get; set; }
public string CreatorType { get; set; }
public int CreatorTargetId { get; set; }
}
public class RootObject
{
public int TargetId { get; set; }
public object ProductType { get; set; }
public int AssetId { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int AssetTypeId { get; set; }
public Creator Creator { get; set; }
public int IconImageAssetId { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
public object PriceInRobux { get; set; }
public object PriceInTickets { get; set; }
public int Sales { get; set; }
public bool IsNew { get; set; }
public bool IsForSale { get; set; }
public bool IsPublicDomain { get; set; }
public bool IsLimited { get; set; }
public bool IsLimitedUnique { get; set; }
public object Remaining { get; set; }
public int MinimumMembershipLevel { get; set; }
public int ContentRatingTypeId { get; set; }
}
use Newtonsoft.Json
var jsonString = #"{""TargetId"":0,""ProductType"":null,""AssetId"":1239281845,""ProductId"":0,""Name"":""β€οΈπππππβοΈπβ€οΈ Red&Black Flannel + Backpack"",""Description"":""Shirt Image"",""AssetTypeId"":1,""Creator"":{""Id"":124026176,""Name"":""TheDestroyerPeter"",""CreatorType"":""User"",""CreatorTargetId"":124026176},""IconImageAssetId"":0,""Created"":""2017-12-12T19:48:24.693Z"",""Updated"":""2017-12-12T19:48:24.693Z"",""PriceInRobux"":null,""PriceInTickets"":null,""Sales"":0,""IsNew"":false,""IsForSale"":false,""IsPublicDomain"":false,""IsLimited"":false,""IsLimitedUnique"":false,""Remaining"":null,""MinimumMembershipLevel"":0,""ContentRatingTypeId"":0}";
var obj = JsonConvert.DeserializeObject<RootObject>(jsonString);
Console.WriteLine(obj.Creator.Name); //"TheDestroyerPeter"
In my import function, i am replacing existing documents or adding new ones using the Upsert option:
var builder = Builders<FacilityDocument>.Filter;
var filter = builder.Eq(x => x.Language.LCID, lcid)
& builder.Eq(x => x.Name, facility.Name)
& builder.Eq(x => x.NameDetailed, facility.NameDetailed)
& builder.Gte(x => x.ImportedDate, new DateTime(DateTime.Now.Year, 1, 1));
collection.ReplaceOne(filter, facility, new UpdateOptions { IsUpsert = upsert });
Now in my POCO class, i have it configured to use GUID instead of an ObjectID, like this:
[BsonId]
[BsonIgnoreIfDefault]
public Guid ID { get; set; }
The problem is that in the database, instead of generating a GUID, its defaulting back to ObjectId:
And what it should be doing, is this (which works when using the regular Insert method):
Much appreciated if anyone have a solution for this.
Update
This is my entire facilitydocument class:
[BsonId]
[BsonIgnoreIfDefault]
public Guid ID { get; set; }
public string Name { get; set; }
public string NameDetailed { get; set; }
public CommuneDocument Commune { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Homepage { get; set; }
public FacilityTypeDocument FacilityType { get; set; }
public FacilityPlacement FacilityPlacement { get; set; }
public int CoursesCount { get; set; }
public CoursesData[] CoursesData { get; set; }
public OwnershipDocument Ownership { get; set; }
public OperationDocument Operation { get; set; }
public string ExternalRemarks { get; set; }
public GisLocationData GisLocationData { get; set; }
public string ContactPersonName { get; set; }
public string ContactPersonEmail { get; set; }
public string InternalRemarks { get; set; }
public bool Active { get; set; }
public LanguageDocument Language { get; set; }
public DateTime ImportedDate { get; set; }
public string ImportedBy { get; set; }
public string UpdatedBy { get; set; }
public DateTime UpdatedDate { get; set; }
public List<ChangeLog> ChangeLog { get; set; }
Update 2
If i set my ID before the replace method, i get an error like this:
A write operation resulted in an error. The _id field cannot be changed from {_id: BinData(3, BF515DEF5743F547BD3EABB1A89DAC4D)} to {_id: BinData(3, 6364DF16640A4346B62E6B866BF76069)}
This is how i set it:
facilityDocument.ID = Guid.NewGuid();
I am using Entity Framework 6.1 in asp.net webform project. When I try to add new object into projects, I am getting Ambiguous match found exception.
I am using database first approach. I do not any manipulation in created models. I have read some questions about that problem. General cause is same named properties and navigation in class. I did not found any same named property.
Can you tell me what i missed?
Thank you
Code:
projects m_NewProject = new projects();
decimal m_CompanyRef = MemberHelperC.getUser().CompanyRef;
DateTime m_EndDate = GeneralHelperC.getCompanyDateTime().AddDays(5);
DateTime m_StartDate = GeneralHelperC.getCompanyDateTime();
customers m_Customer = myEntity.customers.Where(xXx => xXx.CompanyRef == m_CompanyRef).FirstOrDefault();
m_NewProject.ProjectLeadRef = MemberHelperC.getUserID();
m_NewProject.ProjectName = m_ProjectName;
m_NewProject.ProjectStatus = Convert.ToByte(1);
m_NewProject.SourceLangRef = Convert.ToDecimal(comboSourceLang.SelectedValue);
m_NewProject.TargetLangRef = Convert.ToDecimal(comboTargetLang.SelectedValue);
m_NewProject.DomainRef = Convert.ToDecimal(1);
m_NewProject.ProjectYear = GeneralHelperC.getCompanyDateTime()/*DateTime.Now*/.Year;
m_NewProject.EndDate = m_EndDate;
m_NewProject.StartDate = m_StartDate;
m_NewProject.TaskStepNameRef = m_TaskStepNameID;
m_NewProject.CustomerRef = Convert.ToDecimal(m_Customer.RID);
Random m_Random = new Random();
m_NewProject.ProjectUniqueID = m_Random.Next(0, 99999999);
m_NewProject.ProjectTBX = m_Dictionary.RID;
myEntity.projects.Add(m_NewProject);//exception occur this method
myEntity.SaveChanges();
Object Class:
public partial class projects
{
public projects()
{
this.projectnotes = new HashSet<projectnotes>();
this.projectpriceoffers = new HashSet<projectpriceoffers>();
this.projectreferencedoc = new HashSet<projectreferencedoc>();
this.projects1 = new HashSet<projects>();
this.taskstepexceptions = new HashSet<taskstepexceptions>();
this.tbxrelation = new HashSet<tbxrelation>();
this.tmproject = new HashSet<tmproject>();
this.tmrelation = new HashSet<tmrelation>();
this.wizardprojecttasks = new HashSet<wizardprojecttasks>();
this.works = new HashSet<works>();
}
public decimal RID { get; set; }
public string ProjectName { get; set; }
public decimal ProjectStatus { get; set; }
public decimal ProjectLeadRef { get; set; }
public System.DateTime EndDate { get; set; }
public System.DateTime StartDate { get; set; }
public int ProjectYear { get; set; }
public int ProjectUniqueID { get; set; }
public Nullable<decimal> ParentProjectRef { get; set; }
public Nullable<decimal> TMXHeaderRef { get; set; }
public decimal SourceLangRef { get; set; }
public decimal TargetLangRef { get; set; }
public decimal DomainRef { get; set; }
public decimal TaskStepNameRef { get; set; }
public Nullable<decimal> ProjectTBX { get; set; }
public Nullable<decimal> CustomerRef { get; set; }
public virtual customers customers { get; set; }
public virtual domainname domainname { get; set; }
public virtual language language { get; set; }
public virtual language language1 { get; set; }
public virtual ICollection<projectnotes> projectnotes { get; set; }
public virtual ICollection<projectpriceoffers> projectpriceoffers { get; set; }
public virtual ICollection<projectreferencedoc> projectreferencedoc { get; set; }
public virtual ICollection<projects> projects1 { get; set; }
public virtual projects projects2 { get; set; }
public virtual projectstatus projectstatus1 { get; set; }
public virtual tasknames tasknames { get; set; }
public virtual tbxdictionary tbxdictionary { get; set; }
public virtual tmxheaderinterface tmxheaderinterface { get; set; }
public virtual users users { get; set; }
public virtual ICollection<taskstepexceptions> taskstepexceptions { get; set; }
public virtual ICollection<tbxrelation> tbxrelation { get; set; }
public virtual ICollection<tmproject> tmproject { get; set; }
public virtual ICollection<tmrelation> tmrelation { get; set; }
public virtual ICollection<wizardprojecttasks> wizardprojecttasks { get; set; }
public virtual ICollection<works> works { get; set; }
}
}
Are you sure there are no same named property somewhere with different casing? It compiles as case sensative, but executes as case insensitive, so even a few capital letters difference in a same name property could cause a Ambiguous match found exception.
I had the same problem:
I had a table named service linked to the table order.
Inside my partial class order, I was using a property called Service.
//Auto generated:
public virtual service service { get; set; }
//My custom property (Shortned, there was a big String.Format inside):
public String Service { get { return service.ds_name; }}
Case insensitive. :/
TL;DR: Property inside partial class with the same name, but with diffferent caps.
I solved my problem. There is a really ambiguous in my code. CustomerStatus really dublicated.
I think Entity Framework team should improve Ambiguous match found exception details. I have more than 90 tables and very hard to debugging...
Exception occure of these code:
public partial class customers
{
public enum CustomerStatusEnum : long
{
Closed = 3,
Open = 1,
Potential = 2
}
public CustomerStatusEnum CustomerStatus
{
get
{
return (CustomerStatusEnum)Status;
}
}
}
I have a classic Order item in my database:
public partial class ORDERS
{
public ORDERS()
{
this.ORDER_DETAIL = new HashSet<ORDER_DETAIL>();
}
public int ORDER_IDE { get; set; }
public string ORDER_STATE { get; set; }
public decimal ORDER_TOTAL { get; set; }
public decimal ORDER_TAXES { get; set; }
public decimal ORDER_SHIPPING_COST { get; set; }
public decimal ORDER_HANDLING_COST { get; set; }
public Nullable<System.DateTime> ORDER_SHIPPING_DATE { get; set; }
public string ORDER_BILLING_NAME { get; set; }
public string ORDER_BILLING_ADDRESS { get; set; }
public string ORDER_BILLING_CITY { get; set; }
public string ORDER_BILLING_REGION { get; set; }
public string ORDER_BILLING_COUNTRY { get; set; }
public string ORDER_BILLING_POSTAL_CODE { get; set; }
public string ORDER_SHIPPING_NAME { get; set; }
public string ORDER_SHIPPING_ADDRESS { get; set; }
public string ORDER_SHIPPING_CITY { get; set; }
public string ORDER_SHIPPING_REGION { get; set; }
public string ORDER_SHIPPING_COUNTRY { get; set; }
public string ORDER_SHIPPING_POSTAL_CODE { get; set; }
public string ORDER_COMMENT { get; set; }
public decimal ORDER_DETAIL_AMOUNT { get; set; }
public string ORDER_DESCRIPTION { get; set; }
public decimal ORDER_DISCOUNT { get; set; }
public virtual ICollection<ORDER_DETAIL> ORDER_DETAIL { get; set; }
}
As you can see, this items has a collection of ORDER_DETAIL. In my project I want to save the modifications made to the order and keep only the current order details. So I am doing this:
public void SaveOrderModifications(ORDERS _orderToReceive)
{
using (mDb = new DatabaseEntity())
{
mDb.Database.Connection.Open();
var orderQry = from o in mDb.ORDERS
where o.ORDER_IDE == _orderToReceive.mOrderID
select o;
ORDERS originalOrder = orderQry.FirstOrDefault();
if (originalOrder == null)
{
throw new Exception("Invalid operation");
}
mDb.Entry(originalOrder).CurrentValues.SetValues(_orderToReceive);
mDb.SaveChanges();
}
}
So if my original order had 3 items, and my new order has 8, and from this order 2 of the original order were dumped, what do I need to do to effectively only keep the 8 new items? Do I need to iterate through all of them to see which ones are there, and which one aren't there anymore?
EDIT
I have found a solution, which is not elegant and consumes a bit of process:
foreach (var orderDetail in originalOrder.ORDER_DETAIL.ToList())
{
mDb.ORDER_DETAIL.Remove(orderDetail);
mDb.SaveChanges();
}
foreach (var orderDetail in orderToSave.ORDER_DETAIL)
{
mDb.ORDER_DETAIL.Add(orderDetail);
mDb.SaveChanges();
}
it implies that I flush all the older ORDER_DETAIL object before adding the new one, but I'm still looking for a more elegant / better way of doing things.
Typically I do it the same way you are doing it, but I check to see if the item is on the new one and only add and remove the changed items. It adds some elegance because you can use a Linq expression.
Something to the effect of:
foreach (var orderDetail in originalOrder.ORDER_DETAIL.Where(d => !newOrder.ORDER_DETAIL.Contains(d)).ToList())
{
mDb.ORDER_DETAIL.Remove(orderDetail);
mDb.SaveChanges();
}
So I made a datagrid in Silver that auto-generates columns. I call a WCF service that fills this data grid. It displays all but two of the columns. Does any know what causes this?
Here is the function that fulls my class that is bounded to
public List<LightOrder> GetOrder(string code)
{
// Add your operation implementation here
using (amazonproscoutEntities context = new amazonproscoutEntities())
{
return (from c in context.AmazonSKUs
where c.MerchantSKU.StartsWith(code)
select new LightOrder()
{
SKU = c.MerchantSKU,
productname = c.ItemName,
asin = c.ASIN,
//ourprice = c.OurPrice,
bbprice = c.Price,
quantity = c.TotalQty,
rank = c.Rank,
amazon = c.Amazon,
afner = c.AFNer
//w1 = c.w1
}
).Take<LightOrder>(500).ToList<LightOrder>();
}
}
This is the class that is bound the the data grid:
public class LightOrder
{
public string SKU { get; set; }
public string productname { get; set; }
public string itemnumber { get; set; }
public string asin { get; set; }
public string amazon { get; set; }
public decimal ourprice { get; set; }
public string bbprice { get; set; }
public int w1 { get; set; }
public string w2 { get; set; }
public string w3 { get; set; }
public string w4 { get; set; }
public int quantity { get; set; }
public string pendingorder { get; set; }
public string afner { get; set; }
public string order { get; set; }
public string total { get; set; }
public string profit { get; set; }
public string percent { get; set; }
public string rank { get; set; }
}
Are these 2 columns marked by the [DataMember] attribute?
If you marked it, and they are still not appearing, maybe the service reference wasn't generated properly?
It turns out it is the class that is having the issue. It has seemingly ignored those fields.