How to create a MVC Model from SQL Server 2014 Functions - sql

I am using SQL Server 2014 and I have a function that takes start and finish date as parameters and returns a table.
In SQL Server when I call my function I use;
SELECT *
FROM PV_GetLogByDT ('2015-11-01', '2016-03-04')
Now I want to use this function to create a MODEL for my MVC project. How can I do that?
When I do I get this error:
Microsoft Visual Studio
Error
There was an error running the selected code generator:
'Unable to retrieve metadata for 'LTKB.CARD.Models.PV_GetCARDLogByDT_Result'. One or more validation errors were detected during model generation:
CARDNOLIST: : EntityType 'CARDNOLIST' has no key defined. Define the key for this EntityType.
CARDPASSLIST: : EntityType 'CARDPASSLIST' has no key defined. Define the key for this EntityType.
CARDPINLIST: : EntityType 'CARDPINLIST' has no key defined. Define the key for this EntityType.
RESULTLIST: : EntityType 'RESULTLIST' has no key defined. Define the key for this EntityType.
CARDNOLIST: EntityType: EntitySet 'CARDNOLIST' is based on type 'CARDNOLIST' that has no keys defined.
CARDPASSLIST: EntityType: EntitySet 'CARDPASSLIST' is based on type 'CARDPASSLIST' that has no keys defined.
CARDPINLIST: EntityType: EntitySet 'CARDPINLIST' is based on type 'CARDPINLIST' that has no keys defined.
RESULTLIST: EntityType: EntitySet 'RESULTLIST' is based on type 'RESULTLIST' that has no keys defined.
OK

If you use EF it can help you. It explain step by step
http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx

Related

Use #Size annotation on Entity Column amount

"HV000030: No validator could be found for constraint 'org.hibernate.validator.constraints.Length' validating type 'java.lang.Long'. Check configuration for 'amount'",

Sulu: Entity has no field or association error

I'm following Sulu example here: https://github.com/sulu/sulu-workshop/
trying to set translations for custom entity type.
My entity file has getter for field "home_team" defined like:
/**
* #Serializer\VirtualProperty(name="home_team")
*/
public function getHomeTeam(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
return null;
}
return $translation->getHomeTeam();
}
So field is not actually part of that entity, but of it's translation entity since it suppose to be translatable.
When I try to create new object of that entity type it works well. I can see in database that field values are stored well and I don't get any error.
But on overview page instead of list of all objects I get error:
[Semantical Error] line 0, col 73 near 'home_team AS': Error: Class App\Entity\MatchEvent has no field or association named home_team
Any idea what could be wrong here?
If you wanna see the translation in the listView you have to create a real translationEntity, like in the workshop project. In this post it is already explained, how to translate a custom entity correctly.
If you have already created your translationEntity you have to configure the relation of the translation to your main entity via a join. Here is an example in the workshop for this configuration.
Sulu uses optimised queries to create the list-object directly from the database. So the entity itself does not get hydrated or serialised for performance reasons. Thus your virtualProperty is never executed.

Change column name for non-primitive field (navigation) with EF Core

Given the following classes:
public class Mission
{
private MissionCard _missionCard;
}
public class MissionCard
{
}
I would like to create this relationship via Fluent API so that _missionCard is treated as a relationship and can be populated from DB but isn't available as a property on my Mission model.
I can create that relationship with:
modelBuilder.Entity<Mission>().HasOne<MissionCard>("_missionCard");
but by default this creates a FK column named "_missionCard". The docs show that a custom name can be specified when using .Property("property name").FromField("field name") but you cannot use .Property for non-primitive types.
Is it possible to change the column name for a relationship like above?
Managed to resolve this by inverting the relationship:
modelBuilder.Entity<MissionCard>()
.HasMany<Mission>()
.WithOne("_missionCard")
.HasForeignKey(nameof(MissionCard));

Customize the primary key data type for Identity in asp.net core 2 creates problems in UserStore

I need the primary key for my user class in Identity to be long instead of the default string. Following this MS tutorial. So i do all that (just replace GUID in the tutorial with long) and everything was looking good until I was working on created a seed class
var userStore = new UserStore<ApplicationUser>(context);
gives me the squiggles on ApplicationUser with the message:
Error CS0311 The type 'WSCPA_AC.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserStore'. There is no implicit reference conversion from 'WSCPA_AC.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'.
Now I see mention of this sort of problem in the comments at the bottom of the tutorial. Do I have to somehow override the UserStore class, and if so, how?
I think you will need to use the base class of UserStore which has a signature of UserStore<TUser, TRole, TContext, TKey> as follows:
var userStore = new UserStore<ApplicationUser, IdentityRole<long>, TContext, long>(context);
Where TContext is the type of your database context.

Hector API - Create Column Family - key validation class

Hey guys I am trying to load a schema into a Cassandra 0.8.2 database via Hector.
I want to add a column family (in a particular keyspace) & specify its name, comparator type, key validation class, and default validation class via Hector.
I've looked through the documentation here:
https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java
for the function that to do this, but it seems I must have the Column Family already created (via the Cassandra CLI) to specify the default validation class, & key validation class when creating the Column Family via the CLI. Am I correct in this assumption? Am I missing any methods? Is it possible to alter the default validation class & key validation class of a Cassandra column family via Hector?
You can do that with hector. There is an example in CassandraClusterTest where you can see new column families being created with the validation class set. There are methods on BasicColumnFamilyDefinition to set the key validation class and comparator as well.