getting error for a table which I did not create using Entity Framwork Code first approach. error is invalid object name "XXXX" - visual-studio-2013

Initial migration code is below where I never create dbo.StudentEvent1 but I get error when I run my asp.net MVC application using this database.
CreateTable(
"dbo.StudentEvents",
c => new
{
StudentId = c.Int(nullable: false),
EventId = c.Int(nullable: false),
isAttended = c.Boolean(nullable: false),
})
.PrimaryKey(t => new { t.StudentId, t.EventId })
.ForeignKey("dbo.Events", t => t.EventId, cascadeDelete: true)
.ForeignKey("dbo.Students", t => t.StudentId, cascadeDelete: true)
.Index(t => t.StudentId)
.Index(t => t.EventId);
CreateTable(
"dbo.TeacherEvents",
c => new
{
TeacherId = c.Int(nullable: false),
EventId = c.Int(nullable: false),
Duties = c.String(),
})
.PrimaryKey(t => new { t.TeacherId, t.EventId })
.ForeignKey("dbo.Events", t => t.EventId, cascadeDelete: true)
.ForeignKey("dbo.Teachers", t => t.TeacherId, cascadeDelete: true)
.Index(t => t.TeacherId)
.Index(t => t.EventId);

Open your package manager console and Select Default project
then Enable-Migrations is use for Enable Migrations
then add-migrations is added your changes in Migrations
then Update-Database is apply to database
please refer below link : http://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx
thanks

Related

Entity Framework Core: using navigation properties instead of joins

Recently I added Navigation Properties to a EF Core project that didn't have any FK in order to use Include instead of Join in as many queries as possible, but I've found that either the sintax doesn't suit my needs in pretty much all the queries (requires to split into multiple queries) or I'm missing something so I'll put an example, and I want to know, using Navigation Properties how would you get all the Stops with its Line list for a specific dayType?:
Stop
stopId
Point
pointId
stopId?
routeId
Route
routeId
serviceDetailId
ServiceDetail
serviceDetailId
serviceHeaderId
ServiceHeaderDay
serviceHeaderDayId
serviceHeaderId
dayType
ServiceHeader
serviceHeaderId
lineId
Line
lineId
The current working query using Join that I would like to translate using Include:
var query = (await context.Stop
.Join(
context.Point,
(stop) => stop.stopId,
(point) => point.stopId,
(stop, point) => new { Stop = stop, Point = point })
.Join(
context.Route,
(join) => join.Point.routeId,
(route) => route.routeId,
(join, route) => new { Stop = join.Stop, Route = route })
.Join(
context.ServiceDetail,
(join) => join.Route.routeId,
(serviceDetail) => serviceDetail.routeId,
(join, serviceDetail) => new { Stop = join.Stop, ServiceDetail = serviceDetail })
.Join(
context.ServiceHeader,
(join) => join.ServiceDetail.serviceHeaderId,
(serviceHeader) => serviceHeader.serviceHeaderId,
(join, serviceHeader) => new { Stop = join.Stop, ServiceHeader = serviceHeader })
.Join(
context.ServiceHeaderDay,
(join) => join.ServiceHeader.serviceHeaderId,
(serviceHeaderDay) => serviceHeaderDay.serviceHeaderId,
(join, serviceHeaderDay) => new { Stop = join.Stop, ServiceHeader = join.ServiceHeader, ServiceHeaderDay = serviceHeaderDay })
.Join(
context.Line,
(join) => join.ServiceHeader.lineId,
(line) => line.lineId,
(join, line) => new { Stop = join.Stop, ServiceHeaderDay = join.ServiceHeaderDay, Line = line })
.Where(e => e.ServiceHeaderDay.DayType == "L")
.Select(e => new { Stop = e.Stop, Line = e.Line })
.Distinct();
.ToListAsync())
// The query ends here, this next step is just grouping by Stops and inserting each Line list into them.
.GroupBy(e => e.Stop.stopId)
.Select(e =>
{
var stop = e.First().Stop;
stop.Lines = e.Select(e => e.Line).ToList();
return stop;
})
One of the failed attemps made using Include:
context.Stop
.Include(e => e.Points)
.ThenInclude(e => e.Route)
.ThenInclude(e => e.ServiceDetail)
.ThenInclude(e => e.ServiceHeader)
.ThenInclude(e => e.ServiceHeaderDay
Where(e => e.DayType = "L")
// Now I need to Include Line from ServiceHeader, but this is a of type ServiceHeaderDay
// and I think you can't use anonymous objects to carry all the tables you just include
// so I found people repeating the includes like this:
.Include(e => e.Point)
.ThenInclude(e => e.Route)
.ThenInclude(e => e.ServiceDetail)
.ThenInclude(e => e.ServiceHeader)
.ThenInclude(e => e.Line)
// This doesn't seem to work, but also how would be the select to get the Stops with all
// the lines for each Stop here?
.Select(e => ?)
If I understand your problem correctly, your query can be simplified a lot. Include usually is not for querying but for loading related data for modification purposes.
var query = context.Stop
.Where(s => s.Points.Any(p => p.Route.ServiceDetail.ServiceHeader.ServiceHeaderDay.DayType = 'L'))
.Select(s => new
{
Stop = s,
Lines = s.Points.Where(p => p.Route.ServiceDetail.ServiceHeader.ServiceHeaderDay.DayType = 'L')
.Select(p => p.Route.ServiceDetail.ServiceHeader.Line)
.ToList()
});

jira-ruby: issue.save returning false

I am trying to create an issue with jira-ruby in the terminal. So far I have done the following (where username, password, site and project have been replaced with the proper values). I have been able to fetch issues, but not to create them. Jira-ruby return false when i try and save an issue
options = {
:username => "username",
:password => "password",
:site => 'site',
:context_path => '',
:auth_type => :basic
}
client = JIRA::Client.new(options)
issue = client.Issue.build
issue.save({
"fields" => {
"summary" => "blarg from in example.rb",
"project" => {"key" => "mykey"},
"issuetype" => {"id" => "1"}
}
})
=> false
issue.attrs
=> {"errorMessages"=>[], "errors"=>{"issuetype"=>"issue type is required"}, "summary"=>"blarg from in example.rb", "key"=>"somekey", "id"=>"someid", "self"=>"site", "exception"=>{"class"=>"Net::HTTPBadRequest", "code"=>"400", "message"=>"Bad Request"}}
What is the problem?

How to update in mysql using codeigniter

How can I update my data into my database? There is no error but it doesn't update in my database
This is my model
public function updateNewServices($prod_name,$prod_id,$service_type,$service_gl_acc,$min_amnt,
$def_amnt,$max_amnt,$client,$services_id)
{
$services_id = $this->db->escape_str($services_id);
$prod_name = $this->db->escape_str($prod_name);
$prod_id = $this->db->escape_str($prod_id);
$service_type = $this->db->escape_str($service_type);
$service_gl_acc = $this->db->escape_str($service_gl_acc);
$min_amnt = $this->db->escape_str($min_amnt);
$def_amnt = $this->db->escape_str($def_amnt);
$max_amnt = $this->db->escape_str($max_amnt);
$client = $this->db->escape_str($client);
$basic_data = array(
"prod_name" => $prod_name,
"prod_id" => $prod_id,
"service_type" => $service_type,
"service_gl_acc" => $service_gl_acc,
"min_amnt" => $min_amnt,
"def_amnt" => $def_amnt,
"max_amnt" => $max_amnt,
"client" => $client
);
$this->db->where("services_id=",$services_id);
$this->db->update("services",$basic_data);
}
1) First you should change line $this->db->where('services_id', $services_id);
2) second one you should check data type in database and update data value type also .
3) You are using escape_str. so confirm with each data value data type and with db also.

Elasticssearch Nest Synonyms 2.XX

I'm a newbie for elasticsearch and we are evaluate elasticsearch for our webstore. One important feature is the usage of synonyms. Unfortunately I'm not able to create a index with synonyms. Please can anybody help me how I can use the synonyms feature. I didn't find any sample for this feature and elasticsearch 2.xx. The goal should be if I search for Hills the entry of Royal will be find.
I use the following code:
private ElasticClient GetClient()
{
var node = new Uri(ES_URI);
var uri = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(uri).DefaultIndex("product");
var client = new ElasticClient(settings);
return client;
}
public void CreateSynonymIndex()
{
Product product = new Product()
{
Id = "2",
ProductName = "Royal",
Description = "Katzenfutter für Nierkranke"
};
var client = GetClient();
client.DeleteIndex("product");
var syn = new[] { "royal, hills => royal" };
ICreateIndexResponse respose = client.CreateIndex("product", c => c
.Mappings(mp => mp.Map<Product>(d => d.
Properties(p => p.String(n => n.Name(name => name.ProductName).Index(FieldIndexOption.Analyzed)))))
.Settings(s => s
.Analysis(an => an
.Tokenizers(at=>at.Pattern("synonymTokenizer",pa=>pa.Pattern("Test")))
.Analyzers(a=>a.Custom("synonymAnalyser",ca =>ca
.Tokenizer("synonymTokenizer")
.Filters(new List<string> { "synonym" })))
.TokenFilters(tf => tf
.Synonym("synonym", sy => sy.Synonyms(syn)
.Tokenizer("whitespace")
.IgnoreCase(true)))))
);
client.Index(product);
}
public void ES_Search()
{
var client = GetClient();
var response = client.Search<Product>(search => search
.Query(q => q.Bool(b => b
.Should(
// s => s.Match(m => m.Query("sometest").Field(f => f.ProductName).Boost(1.1)),
s => s.Match(m => m.Query("hills").Field(f => f.ProductName).Fuzziness(Fuzziness.EditDistance(1)))
))));
var response1 = client.Search<Product>(s => s.Query(q => q.Term(p => p.ProductName, "hills")));
}
Regards,
Dominik
You have created analyzer with synonyms, but you are not using it. You need to tell elasticsearch that ProductName field should use synonymAnalyser analyzer.
.Mappings(mp => mp.Map<Product>(d => d.
Properties(p => p.String(n => n
.Name(name => name.ProductName)
.Analyzer("synonymAnalyser")
.Index(FieldIndexOption.Analyzed)))))
I noticed few more things though:
remeber that document is not immediately available in elasticsearch after calling client.Index(..) method. It will take some miliseconds. Searching just right after indexing document, you may not find it. You can read more about it here
I don't know if you creat ElasticClient with default index, because you didn't share it. If not, you will have to specify it in your search calls e.g.
client.Search<Product>(s => s.Index("product")).
Hope that helps you.

Symfony 1.4 sfWidgetFormInputFileEditable customization

I am using the sfWidgetFormInputFileEditable widget for my users to upload images.
I would like to see if there's a way to alter the way it works be default. When a user is adding a "new" object, I would like for it to show a generic picture, and when it's an "edit" then it can show the existing pic. I tried writing a PHP conditional statement but that's not working for me because when it's a "new" item I can't pull the parameter "getPicture1" because it doesn't exist.
My widget currently:
$this->widgetSchema['picture1'] = new sfWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/car/'.$this->getObject()->getPicture1(),
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
You have two options (the second one is more easy).
First option: create your own sfWidgetFormInputFileEditable and extends the original.
In a file lib/widget/myWidgetFormInputFileEditable.class.php:
class myWidgetFormInputFileEditable extends sfWidgetFormInputFileEditable
{
protected function getFileAsTag($attributes)
{
if ($this->getOption('is_image'))
{
if (false !== $src = $this->getOption('file_src'))
{
// check if the given src is empty of image (like check if it has a .jpg at the end)
if ('/uploads/car/' === $src)
{
$src = '/uploads/car/default_image.jpg';
}
$this->renderTag('img', array_merge(array('src' => $src), $attributes))
}
}
else
{
return $this->getOption('file_src');
}
}
}
Then you need to call it:
$this->widgetSchema['picture1'] = new myWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/car/'.$this->getObject()->getPicture1(),
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
Second option: check if the object is new then use the default image.
$file_src = $this->getObject()->getPicture1();
if ($this->getObject()->isNew())
{
$file_src = 'default_image.jpg';
}
$this->widgetSchema['picture1'] = new sfWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/car/'.$file_src,
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));

Resources