workflow toolbox not updated with new activity - workflow-foundation-4

I've added to the activity pack the following activity:
namespace TeamFoundation.Build.ActivityPack
{
using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Build.Client;
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class CheckSlothInitialized : CodeActivity
{
[RequiredArgument]
public InArgument<string> DbUser { get; set; }
[RequiredArgument]
public InArgument<string> DbPassword { get; set; }
[RequiredArgument]
public InArgument<string> DbServer { get; set; }
[RequiredArgument]
public InArgument<string> DbName { get; set; }
protected override void Execute(CodeActivityContext context)
{
string connString = String.Format(
"data source={0};Integrated Security=false;Initial Catalog={1};User ID={2};Password={3}",
DbServer, DbName, DbUser, DbPassword);
}
}
}
After that I compile it I can't find it in the toolbox. I'm going to choose items in the toolbox and choosing the dll of my activity, but even then I can't find it in the list of System.Activities Components.

Please follow these check points.
Clean and rebuild your solution.
If your activity is in independent project (activity library) and you are referring this activity in a project containg xaml or xamlx file make sure all referenced dll should be added in reference.
Try to add this activity as code behind in a workflow and execute it, is there any exception thrown?

Related

Creating table Entity Framework Core and SQLite

Using Microsoft.EntityFrameworkCore.SQLite, I'm attempting to create a code level creation of a database, and add a simple row to a table. I get the error, SQLite error: no such table Jumplists.
From last to first, here are the classes
using JumpList_To_Clipboard.Data.Tables;
using Microsoft.EntityFrameworkCore;
namespace JumpList_To_Clipboard.Data
{
public class DataSQLite : IData
{
public const string DATABASE = "data.sqlite";
public DataSQLite()
{
using (var db = new SQLiteDbContext(DATABASE))
{
// Ensure database is created with all changes to tables applied
db.Database.Migrate();
db.JumpLists.Add(new JumpList { Name = "Default" });
db.SaveChanges(); // Exception thrown here
}
}
}
}
The DbContext class
using JumpList_To_Clipboard.Data.Tables;
using Microsoft.EntityFrameworkCore;
namespace JumpList_To_Clipboard.Data
{
class SQLiteDbContext : DbContext
{
readonly string db_path;
public DbSet<JumpList> JumpLists { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<Item> Items { get; set; }
public SQLiteDbContext(string database) : base()
{
db_path = database;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(string.Format("Data Source={0}", db_path));
}
}
}
The JumpList class
using System.Collections.Generic;
namespace JumpList_To_Clipboard.Data.Tables
{
public class JumpList
{
public int JumpListId { get; set; }
public string Name { get; set; }
public List<Group> Groups { get; set; }
public List<Item> Items { get; set; }
}
}
The other two classes aren't worth repeating here, and don't give errors.
When I use the firefox sqlite extension to look at the data.sqlite file, none of my three tables are listed.
The command db.DataBase.Migrate says it
Applies any pending migrations for the context to the database.
What are pending migrations? I can't seem to find any documentation anywhere on these.
I'm combining examples from:
https://learn.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
https://blogs.msdn.microsoft.com/dotnet/2016/09/29/implementing-seeding-custom-conventions-and-interceptors-in-ef-core-1-0/
Edit: If I replace db.Database.Migrate(); with db.Database.EnsureCreated(); it works. From the documentation, Migrate() is the same, but lets you create updates to the table structures, where EnsureCreated() does not. I'm confused.
So,
Microsoft has a serious issue making decent documentation, but I did find a site that has somewhat dated documentation for Learning Entity Framework Core, specifically migrations which is in the link.
At the top, it mentions,
If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations.
Which led to the Package Manager Console page which states right at the top, that you need to have:
If you want to use the Package Manager Console to execute migrations command, you need to ensure that the latest version of Microsoft.EntityFrameworkCore.Tools is added to your project.json file.
The problem is, there is no project.json file anywhere in my project (or solution). After some searching, I found that via NuGet, to add Microsoft.EntityFrameworkCore.Tools
Then via Tools > NuGet Package Manager > Package Manager Console I was able to run the add-migration InitialDatabases command. The last part InitialDatabases is the name of the class it creates for you, and sticks in a folder called Migrations at the base of the project.
Now when:
context.Database.Migrate();
is run, all is well!
Try this (worked for me in a project a few months ago, i don't remember why):
public virtual DbSet<JumpList> JumpLists { get; set; }
public virtual DbSet<Group> Groups { get; set; }
public virtual DbSet<Item> Items { get; set; }
Also i had to use LONG instead of INT for classes ID because sqlite uses LONG as default for table ID, so after when you do a CRUD operation it fails because it can't compare/convert/cast LONG(64) to INT(32).

(are you missing a using directive or an assembly reference?)

i am writing common business logic class in App_code folder for connecting to database using EFW.but showing the following error " Error 1 The type or namespace name 'job' could not be found"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
namespace WebApplication6.App_Code
{
public class BlCommon
{
public List<job> GetJobs()
{
pubs2012Entities pubsobject = new pubs2012Entities();
var x = pubsobject.jobs.ToList<job>();
return x;
}
}
}
and class generated by EFW from jobs table is
namespace WebApplication6.App_Code
{
using System;
using System.Collections.Generic;
public partial class job
{
public short job_id { get; set; }
public string job_desc { get; set; }
public byte min_lvl { get; set; }
public byte max_lvl { get; set; }
}
}
Seem you dont have a reference to assembly wich contain mentioned class
Ok I got it:
Public List<job> GetJobs()
{
pubs2012Entities pubsobject = new pubs2012Entities();
var x = pubsobject.jobs.ToList<job>();
return x;
}
Click on Job, Move the mouse cursor over the blue dash that appear at the bottom of
job click Generate Class and then move your Job.cs code to your new job.cs class and
delete the old one.

Reading values from DBML(having stored procedure)

I have a dbml that has stored procedures dragged off.I have EmployeeModel class that has get and set propertise .
I have an interface IEmployee and a Repository Employee Repository that has the implementation of the methods.Please refer the code.In Stored procedure GetRoles i just have SELECT * FROM ROLE .
In repository how to loop through the resultset.Can i change ISingleResult to IMultipleResult in dbml designer file?
EmployeeModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcWebsite.Models
{
public class EmployeeModel
{
public int RoleId { get; set; }
public string RoleName { get; set; }
public string Description { get; set; }
public string TaskMark { get; set; }
public int RoleFlag { get; set; }
}
}
IEmployee:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcWebsite.Models;
namespace MvcWebsite.DAL
{
public interface IEmployees
{
IList<EmployeeModel> ListAll();
// void Save(EmployeeModel employ);
}
}
EmployeeRepository.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcWebsite.Models;
using System.Data.Linq;
namespace MvcWebsite.DAL
{
public class EmployeeRepository:IEmployees
{
private DataDataContext _dataContext;
public EmployeeRepository()
{
_dataContext = new DataDataContext();
}
public IList<EmployeeModel> ListAll()
{
//IMultipleResults result =_dataContext.GetRoleDetails();
//var Emps = result.GetResult(EmployeeModel);
List<EmployeeModel> emp = _dataContext.GetRoleDetails();
// foreach (GetRoleDetailsResult role in Emps)
// {
// role.Description=Emps.
// }
return Emps.ToList();
}
}
}
You can loop through the resultset as below:
List<EmployeeModel> employeeModels = new List<EmployeeModel>();
foreach (EmployeeModel employeeModel in _dataContext.GetRoleDetails())
{
employeeModels.Add(employeeModel);
}
Or you can use System.Linq.Enumerable class ToList<> method as below:
List<Product> products = context.GetProducts().ToList<Product>();
IMultipleResults is used when stored procedure is returning more than one result sets. However when you drop such procedures on to the designer, it doesn't generate IMultipleResults. For this you can change the designer generated code to use IMultipleResults as below:
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetCustomerAndProducts")]
[ResultType(typeof(Customer))]
[ResultType(typeof(Product))]
public IMultipleResults GetCustomerAndProducts()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}
However, it would overwrite your modifications when you do any changes in the designer because it would regenerate the code. To avoid this you can use partial classes.
Or you can also use SqlMetal tool. It is a command-line tool that generates code and mapping for the LINQ to SQL component of the .NET Framework. This tool generates IMultipleResults. You can get the details for this tool here:
http://msdn.microsoft.com/en-us/library/bb386987.aspx
Edited:
Repository functionality will be same regardless of you work in ASP.Net Mvc or WinForms or any other presentation layer.
You can change your repository function to below:
public List<EmployeeModel> ListAll()
{
return _dataContext.GetRoleDetails().ToList<EmployeeModel>();
}
Or:
public List<EmployeeModel> ListAll()
{
List<EmployeeModel> employeeModels = new List<EmployeeModel>();
foreach (EmployeeModel employeeModel in _dataContext.GetRoleDetails())
{
employeeModels.Add(employeeModel);
}
return employeeModels;
}

Entity framework how to map this relationship?

I have
User:
-ID
-Name
Badge
-ID
-Name (E.G "User has made 100 posts", the same relationship as Stackoverflow)
So I've realised I need a third table, (as badges are defined in the DB aswell so I've created:
UserBadge
-ID
-User
-Badge
So now in my User class I have
List<UserBadge> Badges;
Problem is, I'm going
Users.Find(1).Badges.Where(x => x.User == user && x.Badge = badgeIWant)
.FirstOrDefault();
(Or something similar) Because... EF doesn't have the intelligence (I'm guessing) to automatically know that "Badges" should only include the ones where the User matches.
How should I do this? Was thinking I could have a custom getter for Badges, that has that LINQ conditional in it...
This is EF 4.3 code first:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
namespace ConsoleApp
{
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Badge> Badges { get; set; }
}
public class Badge
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
}
public class Context : DbContext
{
public Context()
: base("Votes")
{
}
public DbSet<User> Users { get; set; }
public DbSet<Badge> Badge { get; set; }
}
class Program
{
static void Main(string[] args)
{
Context context = new Context();
User user = context.Users.Include("Badges").Where(u => u.ID == 1).SingleOrDefault();
if(user != null)
{
//write your code.
}
Console.ReadKey();
}
}
}
I've tested it and this should work. This would typically be a many to many relationship because User can have many badges and 1 badge can belong to many users. If you run this code, you will find EF creates BadgeUsers table with BadgeID and UserID as foreign keys. From there on you can query and EF knows which badges you talking about.
If you want to get all the badges of the user then just use users.Find(1).Badges. EF will automatically filter the badges related to the user.

how can i solve : the type or namespace name 'DbModelBuilder' Could not be found

i created an MVC Project for test on another PC last night
it worked good on that PC but when i want to build it on my own PC it i give error :
the type or namespace name 'DbModelBuilder' Could not be found(are you missing...)
how can i solve it ?
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;
namespace University.Models
{
public class SchoolContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
public DbSet<Course> Courses { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
Does this dll exist in your solution?
If it points to DbModelBuilder.dll in a folder in the other PC, it won't run successfully in your PC.
Edit:
Can you see this ?
Looks like you forgot an assembly reference to System.Data.Entity.

Resources