I have been struggling with peta poco and related classes and are getting the error "Couldn't find split point between PetaPocoProofOfConcept.Resource and PetaPocoProofOfConcept.BookingType".
My two classes are:
[TableName("Resource"), PrimaryKey("Id")]
public class Resource
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public long MinTimeSpan { get; set; }
public long MaxTimeSpan { get; set; }
public long FixedTimeSpan { get; set; }
public DateTime ActiveStart { get; set; }
public DateTime ActiveEnd { get; set; }
public bool Active { get; set; }
public BookingType BookingType { get; set; }
public int StatusId { get; set; }
}
[TableName("BookingType"), PrimaryKey("Id")]
public class BookingType
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
I get the error when executing this line of code:
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var resources = new Database(connection).Query<Resource, BookingType>("SELECT * FROM [Resource]").ToList();
}
I have been reading some documentation but cant seem to find any answer of why this fails. Does anyone know?
Thanks :)
That's not the way Petapoco multi mapping works.
You can use that syntax in this way:
var posts = db.Fetch<post, author>(#"
SELECT * FROM posts
LEFT JOIN authors ON posts.author = authors.id ORDER BY posts.id
");
This gives you two list with Posts and Authors.
If you want to perform more complex mappings (like your example), you need to write a callback like this:
var posts = db.Fetch<post, author, post>(
(p,a)=> { p.author_obj = a; return p; },
#"SELECT * FROM posts
LEFT JOIN authors ON posts.author = authors.id ORDER BY posts.id
");
More info on Petapoco Multi mapping
Related
I have created an observable collection
public ObservableCollection<DatagGridCollection> combine_audit_final_collection { get; set; }
which I'm trying to populate via linq result
var d = (from p in Auditcollectiondata
from c in Finalcollectiondata
where c.sno == p.sno
select new
{
p.sno,
p.AuditID,
p.claimnumber,
p.QueryID,
p.DateWorked,
p.UserID,
p.Line,
p.Dos,
p.CPT,
p.Units,
p.amtBilled,
p.RecoupUnit,
p.reocupamts,
p.ScioNote,
p.Linelevelstatus_valuetext,
p.providerNote,
c.ID_finalstatus,
c.FinalStatus
});
The join works fine but when I try to insert the results into observable collection. I'm getting casting error.
combine_audit_final_collection = new ObservableCollection<DatagGridCollection>((ObservableCollection<DatagGridCollection>) d);
The combine_audit_final_collection will be binded into the datagrid. Though there is no compile error I'm getting parsing exception at runtime while execute.
Update : I try to join two observable collection using sno and inserting the result into another observable collection 'combine_audit_final_collection'. If my approach is wrong please let me know any other approach.
public class DatagGridCollection
{
public bool update { get; set; }
public int sno { get; set; }
public string AuditID { get; set; }
public string claimnumber { get; set; }
public string QueryID { get; set; }
public DateTime DateWorked { get; set; }
public string UserID { get; set; }
public string Line { get; set; }
public string Dos { get; set; }
public string CPT { get; set; }
public string Units { get; set; }
public string amtBilled { get; set; }
public string RecoupUnit { get; set; }
public string reocupamts { get; set; }
public string ScioNote { get; set; }
public string Linelevelstatus_valuetext { get; set; }
public string providerNote { get; set; }
public int final_status_sno { get; set; }
public string Finalstatus { get; set; }
}
Are you sure that your ObservableCollection is a collection of DataGridCollections? Is every element of your collection a DataGridCollection?
If not, but it is in fact a collection of MyType, change the word DataGridCollection below with MyType
Anyway, if you would check in your debugger the type of object d, you would notice that it is not an IEnumerable<DatagGridCollection>.
Just change your code to:
select new DataGridCollection()
{
p.sno,
...
If you want to detect the cause of this kind of errors in the future, my advice would be not to use the word var too much, and not to do too much statements at once.
IEnumerable<DataGridCollection> d = ...
Select new DataGridCollection
{
...
};
combine_audit_final_collection = new ObservableCollection<DatagGridCollection>(d);
It will be much easier to find your errors.
I have a requirement to fetch all work items from TFS and store every detail into SQL DB. I am able to take everything from TFS without much trouble. But not getting a perfect way for pushing these data into SQL Db. I thought about looping through the resulting object and push them individually, but its very time and resource consuming. So looking forward to a perfect clean solution.
Here is the code I am using
public void GetAllTfsWorkItems()
{
//List<string> projects = new List<string>();
//projects = LoadProjectsList();
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_uri));
var workitemstore = new WorkItemStore(tpc);
Query query = new Query(workitemstore, "select * from workitems where [System.WorkItemType] in ('Epic','Bug','Feature','Product Backlog Item','Task') ");
WorkItemCollection wic = query.RunQuery();
List<string> PE = new List<string>();
List<string> fields = new List<string>();
foreach(WorkItem wi in wic)
{
PE.Add(wi.Title);
var parentlink = wi.WorkItemLinks.Cast<WorkItemLink>().FirstOrDefault(x => x.LinkTypeEnd.Name == "Parent");
WorkItem parentworkitem = null;
int parentid;
if(parentlink!=null)
{
parentid = parentlink.TargetId;
//parentworkitem = workitemstore.GetWorkItem(parentlink.TargetId);
}
}
}
public class TfsWorkItems
{
public int ID { get; set; }
public string WorkItemType { get; set; }
public string Title { get; set; }
public string AreaPath { get; set; }
public string AssignedTo { get; set; }
public string BoardColumn { get; set; }
public string State { get; set; }
public string Description { get; set; }
public string IterationPath { get; set; }
public string CreatedDate { get; set; }
public string Tags { get; set; }
public string AcceptanceCriteria { get; set; }
public string BusinessValue { get; set; }
public string Priority { get; set; }
public string Effort { get; set; }
public string PCode { get; set; }
public string Parent { get; set; }
public string Project { get; set; }
public string TeamName { get; set; }
public string DomainName { get; set; }
}
The loop takes around 10-15 mins to finish. But I expect some easier solution there like the direct mapping of WorkItem array object into to my custom class TFSWorkItems and some method to push the data together. Please suggest an easier solution. deadline is reaching badly because I guess time running very fast in 2019.
Please note there are around 250k+ items in TFS
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; }
}
I have the following models
Patient Class:
public class Patient
{
public int PatientID { get; set; }
public virtual Salutation salutation { get; set; }
public int SalutationID { get; set; }
public string Surname { get; set; }
public string Firstname { get; set; }
[Display(Name = "Date of Birth")]
[DisplayFormat(DataFormatString="{0:d}", ApplyFormatInEditMode=true)]
public DateTime DOB { get; set; }
public string RegNo { get; set; }
public DateTime RegDate { get; set; }
public string Occupation { get; set; }
}
VatalSigns Class
public class VitalSign
{
public int VitalSignID { get; set; }
public string Sign { get; set; }
[Display(Name = "Lower Limit")]
public int? LowerHold { get; set; }
[Display(Name = "Upper Limit")]
public int? UpperHold { get; set; }
[Display(Name = "Unit Of Measurment")]
public string Units { get; set; }
}
PV class that stores VitalSigns for each patient
public class PVSign
{
public long PVSignId { get; set; }
[Display(Name = "Patient")]
public int PatientID { get; set; }
public VitalSign VitalSigns { get; set; }
//public IList<VitalSign> VitalSigns { get; set; }
public Patient patient { get; set; }
}
Now the problem I have is that I have not been able to get display on one from to enter the details. I want to select the Patient and the different Vitals signs will appear and I will save the ones I need to the PVSign table.
I have tired all sorts of samples from the web. You can see from the code below, this is the index stub:
public ActionResult Index()
{
var pVSigns = db.PVSigns.Include(p => p.patient).Include(p => p.PVSignId).Include(p => p.VitalSigns);
//var pVSigns = from o in db.Patients join o2 in db.PVSigns
//List<object> myModel = new List<object>();
//myModel.Add(db.Patients.ToList());
//myModel.Add(db.VitalSigns.ToList());
//return View(myModel);
return View(pVSigns.ToList());
}
How to I solve this issue. I am new to MVC, if it was Webforms, I would have been through with this project.
Thank you.
There is no single answer(solution) to this(your) problem. It depends on how you want to design/build/achieve your solution.
The simple, brute solution : Just have a view model as a wraper that has as his properties the classes(models) you made and work around that,
public class FullPatientDetailsViewModel
{
public Patient { get; set;}
public List<PVSign> PatientPvSigns { get; set;} // Patien PV Signs
}
Or use just a PatientViewModel and load his PVSigns async with Ajax.
There is no simple best solution, it all depends about what do you want to achieve as a bigger picture.
I've answered a similar question here. As Alexandru mentioned, the easiest and most straightforward way would be to wrap your models inside a ViewModel. You can read about other ways to implement this here.
i currently have a linq to entities model set up as follows
each Sample has a collection Of Tests
each Test has a collection of Results
Each Result has Status property valuing whether it is Available or Completed
how would i write a linq query that would:
get the samples that have available Results
retaining only the tests that have available results
and only the results in each test that are available
having trouble getting my head around this problem and help with getting this
written would really help alot
Classes:
public class Sample
{
public Sample()
{
Tests = new List<Test>();
}
public int Id { get; set; }
public string IdText { get; set; }
public DateTime SampleDate { get; set; }
public DateTime LoginDate { get; set; }
public string Container { get; set; }
public string Product { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public virtual SamplePoint SamplingPoint { get; set; }
public virtual SampleTemplate SampleTemplate { get; set; }
public virtual Customer ForCustomer { get; set; }
public virtual ICollection<Test> Tests { get; set; }
public class Test
{
public Test()
{
Results = new List<Result>();
}
public string Id { get; set; }
public string Status { get; set; }
public string Analysis { get; set; }
public string ComponentList { get; set; }
public virtual Instrument InstrumentUsed { get; set; }
public virtual ICollection<Result> Results { get; set; }
public virtual Sample ForSample { get; set; }
}
public class Result
{
public string Id { get; set; }
public string TestNumber { get; set; }
public string Status { get; set; }
public string Analysis { get; set; }
public string ComponentName { get; set; }
public string Text { get; set; }
public string Units { get; set; }
public double Value { get; set; }
public int OutOfRange { get; set; }
public DateTime SampledDate { get; set; }
public DateTime SampleLoginDate { get; set; }
public string SamplePoint { get; set; }
public virtual Sample ForSample { get; set; }
public virtual Test ForTest { get; set; }
}
If I understand your table structure then it's fairly easy to query down to get the results that you're interested in.
I put together a simple set of classes to test the results.
public static class db
{
public static List<Sample> Samples = new List<Sample>();
}
public class Sample
{
public string Name;
public List<Test> Tests = new List<Test>();
}
public class Test
{
public string Name;
public List<Result> Results = new List<Result>();
}
public class Result
{
public string Name;
public string Status;
}
And I created this set of test data:
From here it is easy to query the data down to just available results:
var query =
from s in db.Samples
from t in s.Tests
from r in t.Results
where r.Status == "Available"
select new { Sample = s.Name, Test = t.Name, Result = r };
Which gives me this data:
But that doesn't group the data by Sample and Test properly.
One way to do it properly is to create new Sample & Test objects that contain only the available results, like so:
var query =
from s in db.Samples
from rt in (
from t in s.Tests
from r in t.Results
where r.Status == "Available"
group r by t into rts
select new Test()
{
Name = rts.Key.Name,
Results = rts.ToList()
})
group rt by s into srts
select new Sample()
{
Name = srts.Key.Name,
Tests = srts.ToList()
};
This produces this result:
However, it might not be possible, or desirable, to create new instance of objects that look like actual entities but are not actually from the database. It might be possible to accidentally persist one of these objects back to the database and wipe out correct records!
So, an alternative, which I think is the best, is to create a nested structure that contains the unmodified database entities and includes the available tests in an extra properly all while keeping the nested structure!!
Here's how:
var query =
from s in db.Samples
from rt in
(from t in s.Tests
from r in t.Results
where r.Status == "Available"
group r by t into rts
select new
{
Test = rts.Key,
AvailableResults = rts.ToArray()
})
group rt by s into srts
select new
{
Sample = srts.Key,
AvailableTests = srts.ToArray()
};
And this produces:
With these results you still have access to the unchanged Sample and Test objects, but all filtered by the available results.
Let me know if this helps.
Without seeing your actual class structure, I'm hoping this can help in some way:
var testsWithAvailableResults = from test in dbContext.Tests
select new {
Results = (from result in test.Results where result.Status == "Available")
};