## entity framework – Is it considered a bad practice to include methods in classes that comprise an EF model?

There is no technical limitation here. EF entity classes can have methods. Those methods do not impact the de/serialization of the entities, so there’s no conflict.

That being said, it raises red flags and is generally not a good idea.

For one, your persistence logic and business/domain logic should be separated layers. Since the EF entity belongs to the persistance layer, and validation (or general operations) belong to the business/domain layer, these logically shouldn’t find themselves in the same class definition.

Is it better to create a repository for the class, and implement validation in the repository?

EF brings with it some basic data validation, but I would not use that as my business validation, but rather as a last line of defense in case the business logic fails us in some unexpected way.

I would instead validate the DTO which is passed to the business layer, and use that as my main validation logic. When validation passes, the business layer can then talk to the persistence layer and the persistence layer (usually a repository) doesn’t need to explicitly validate anything further.

That being said, if you have an application with several data stores, and those stores have different validation rules, there can be value from having the persistence layer do its own round of validation. But that’s not the most common scenario. The main business validation should generally be situated in the business layer, not the persistence layer.

Or to create validation classes per entity?

Generally speaking, I do separate my domain models from their validation logic. As far as I’m concerned, these are two separate responsibilities and it’s beneficial to keep them separated.

This ensures that validation rules can be altered without impacting the model itself. This can be useful either during development, or if your application has a dynamic validation set that can be altered during runtime (for example, we make applications where the admin end users can set their own validation rules, so we dynamically “pick and mix” our validators).

As per Ben Cottrell’s suggestion in the comments, I would also suggest looking at FluentValidation as it helps you in keeping your validation logic separate from the rest of your logic.

I think there is no “best” approach, but in your opinion, where should the Validation method be implemented?

Context is key here. If this is a quick and dirty home project with no long life expectancy, just bang it in wherever it works. I do not apply my own clean coding advice to small tools I hack together once in a while, as the effort does not outweigh the benefit if I don’t intend to use the application for a long time.

If this is a professional project or a personal project where long term longevity is a relevant consideration, at the very least keep the persistence and business/domain logic separated.

If this is an enterprise-grade project, I’d advocate keeping the (business/domain) validators separate from the business logic/DTOs themselves to further promote maintainability and loose coupling.

## higher category theory – On how Simpson’s model structure on Tamsamani \$n\$-prenerves is cofibrantly generated

I was reading through “A closed model structure for $$n$$-categories, internal $$Hom$$, $$n$$-stacks and generalized Seifert Van-Kampen” by Simpson and was struggling to piece together the argument he made for decomposing morphisms into a trivial cofibration followed by a fibration (on pp. 45-46).
Briefly, I’m failing to understand why the argument by Jardine in Lemma 2.4 in “Simplicial Presheaves” can be applied in this setting.

I’ll try to summarise the important points for discussion to get to my main issues.

• the model structure is over the category of presheaves on $$Theta^n$$ (called prenerves), which is a quotient of the $$n$$-fold product of the simplex category $$Delta$$ by declaring all objects of the form $$(m_1,dots,m_k,0,*,dots,*)inDelta^n$$ to be the same. (It’s defined explicitly on p. 5)
• cofibrations in this model structure are those that are levelwise monomorphisms, except at the top level. This is defined precisely on p. 12, but the point for this post is that (trivial) cofibrations are not necessarily monic

On pp. 45-46, Simpson argues that the trivial cofibrations are generated by those whose domain and codomain are both bounded (where $$A:(Theta^n)^{mathrm{op}}tomathbf{Set}$$ are said to be bounded if $$A_M$$ is countable for every $$MinTheta^n$$).
The argument starts by demonstrating that for any trivial cofibration $$Ato C$$ and any bounded subpresheaf $$Bsubseteq C$$, there are bounded subpresheaves $$Bsubseteq B_omegasubseteq C$$ and $$A_omegasubseteq Atimes_CB_omega$$ (he writes $$Atimes_BB_omega$$ but I imagine this is a typo) such that the induced map $$A_omegato B_omega$$ is also a trivial cofibration.

From here, he appeals to the argument made by Jardine in Lemma 2.4, saying that “the rest of (it) works.” This is where I fail to make the connection, and it might possibly be because I don’t fully understand his argument either, so I will recount it below (doing my best to fill in details):

Jardine was working with simplicial presheaves over a small site $$mathcal C$$, and here the cofibrations were given by the (levelwise) monomorphisms.
As the presheaves were over a small category, we can find a cardinal $$alpha > 2^{|mathcal C_1|}$$, from which we can call a simplicial presheaf $$X$$ $$alpha$$bounded if $$|X_n(U)| for every $$Uinmathcal C$$ and $$ngeq0$$. Lemma 2.4 demonstrates that the trivial cofibrations are then generated by those whose domains and codomains are both $$alpha$$-bounded.

The argument starts by showing that for any trivial cofibration $$i:Ato C$$ and any $$alpha$$-bounded subpresheaf $$Bsubseteq C$$, there is an $$alpha$$-bounded subpresheaf $$Bsubseteq B_omegasubseteq C$$ such that $$Atimes_CB_omegato B_omega$$ is a trivial cofibration. (Since $$i$$ is monic, we get that $$Atimes_CB_omega$$ is also $$alpha$$-bounded.) I can see that Simpson sets up the analogous result for prenerves, including $$A_omega$$ to account for the possibility that $$Atimes_CB_omega$$ is too big in his case.

Jardine then shows that if $$p:Xto Y$$ has the right lifting property against all trivial cofibrations with $$alpha$$-bounded domain and codomain, then it will have the right lifting property against any trivial cofibration $$i:Ato C$$.
To do so, he uses Zorn’s lemma on “partial lifts” which are diagrams

with $$i’$$ a trivial cofibration and $$Bneq A$$. (Honestly, I’m not sure why we need to assert $$Bneq A$$ here.)
The ordering on partial lifts is given by monomorphisms $$Bhookrightarrow B’$$ which respect the maps $$i$$, $$j$$, $$theta$$ (though I am uneasy about this since such monomorphisms are not necessarily unique).
An upper bound to any chain $$(B_lambda)_lambda$$ is then just the colimit $$varinjlim_lambda B_lambda$$.

To show that there is at least one such partial lift, Jardine takes any $$alpha$$-bounded subobject $$B’subseteq C$$ not contained in $$A$$ such that $$Atimes_CB’to B’$$ is a trivial cofibration, and pushes this out along $$Atimes_CB’to A$$ to obtain another trivial cofibration $$i’:Ato B$$.
The map $$p:Xto Y$$ admits a lift against $$Atimes_CB’to B’$$ by assumption, and the lift will factor uniquely through the pushout to give $$theta:Bto X$$. (If we didn’t assert $$Bneq A$$ earlier, $$B=A$$ would have also demonstrated this fact.)

By Zorn’s lemma, there must then be a maximal partial lift $$B^*$$ and the claim is that $$B^*=C$$ (thus providing a lift against $$i$$).
The reasoning is that $$C$$ is a filtered colimit of its $$alpha$$-bounded subpresheaves (and we can restrict to those $$B’$$ for which $$Atimes_CB’to B’$$ is a trivial cofibration).
Thus, a maximal element would form a cocone for the partial lifts these subpresheaves induce, and this must factor uniquely through $$C$$, giving a map $$Cto B^*$$, which (I think) is inverse to $$j^*:B^*to C$$ (but even if it isn’t, we can use $$Cto B^*xrightarrow{theta^*}X$$ as a lift anyway). $$square$$

When trying to port this to Simpson’s case, the only change I think needs to be made is that when showing that the system of partial lifts is nonempty, you replace the trivial cofibration $$Atimes_CB’to B’$$ in the above argument with the trivial cofibration $$A_omegato B_omega$$, and push this out along $$A_omegasubseteq Atimes_CB_omegato A$$, then the rest of the argument should follow through virtually unchanged.

What makes me uneasy is that if the above were true, then I think the same argument can be used to “prove” the false claim that a map $$f:Xto Y$$ is bijective if any $$Cto Y$$ factors through $$f$$ (this property is satisfied by any surjective map, modulo the axiom of choice).
The reason would be that the only part of Jardine’s/Simpson’s argument that uses properties of trivial cofibrations is when constructing $$A_omegato B_omega$$ (where for Jardine, $$A_omega=Atimes_CB_omega$$), so I could use the rest of the argument for any class of morphisms so long as I can provide a substitute for this construction.

In particular, I could replace “trivial cofibrations” with “arbitrary maps of $$mathbf{Set}$$” and say that for any map $$Ato C$$ of sets, and any countable subset $$Bsubseteq C$$, then I can produce another map of sets $$A_omegato B_omega$$ where I take $$Bsubseteq B_omegasubseteq C$$ to be $$B_omega := B$$ and $$A_omega := varnothing$$.
Tracing out this argument, it would follow that a map of sets has the RLP against all maps (making it a bijection) if and only if it has lifts against the maps $$varnothingto B$$ for $$B$$ countable, because the only lifts that are ever needed in the rest of Jardine’s argument are given against those $$A_omegato B_omega$$.

This line of reasoning is clearly false (since the conclusion is), but I’m struggling to see at which point my understanding breaks down. Is there a nuance to Jardine’s argument that I’m overlooking, or somewhere else where the “trivial” part of a trivial cofibration is important that I missed?

## magento2 – How to call the getId() function on an instantiated resource Model

this is how i used to get an Id from a model:

`````` /** @var TopExampleModuleModelexample \$object */

\$object->getId()
``````

I am aware that the load method of the model will be deprecated.

I understand that the correct way to load is to use the Resource Model. My issue however is that the resourceModel does not have getData() or getId() methods.

How then can I get the Id of the instantiated model if there is no
\$this->getId() method.

This is how I now call it:

``````/** @var TopExampleModuleModelexample \$object */
\$model = \$this->modelFactory->create();
\$object =  \$this->viewResource->load(\$model, \$id,'custom_field');

\$object->getId()
``````

## nonlinearmodelfit – non-linear model fit function not working

I have attempted to exercise a non-linear model fit to my data, `dadtAbs`, and got the following puzzle

``````nlm =
NonlinearModelFit(
Transpose({Table(t, {t, 1, tmax}),dadtAbs}),
(1 - aaa)*bbb*NSPI(bbb, ddd, population, t) *
(1 - ddd)*(population - NSPI(bbb, ddd, population, t)),
{aaa, bbb, ddd},
t)
``````

where `dadtAbs` is a list, population is a known constant, `aaa`, `bbb`, `ddd` are the desired answers, and `t` is the variable.

When I queried `nlm`, I got

``````(0.)
``````

Here is the function `NSPI`:

``````NSPI(alpha_, delta_, population_, tt_) :=
population/(1 + (population - 1)*Exp(-alpha*population*(1 - delta)*tt))
``````

population is a large constant, for example, 1000000

## python – Django Appointment Model

I am building a doctor appointment app with Django and Django Rest Framework. The app will have the functionality for secretaries to add appointments to a Doctor’s calendar, and each Doctor may have more than one clinic (and multiple secretaries).

I build this `Calendar` Model to store the availability information of a doctor, which needs to basically inform:

• on a given day, at what time the doctor starts and finishes work
• on a given day, at what time the doctor starts and finishes their break time (if they do).

Is this the optimal way to do it?

``````class Calendar(models.Model):
doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE, related_name="appointments")
clinic = models.ForeignKey(Clinic, on_delete=models.CASCADE, related_name="appointments")
monday_start =  models.TimeField()
monday_end =  models.TimeField()
monday_break_start =  models.TimeField()
monday_break_end =  models.TimeField()
# continues for every single day of the week
``````

## deep learning – Cnn pre trained model feature extraction

is global avg the best option or fc1 layer for feature extraction and pass further to another model?
what can be another option to extract features or retrain

``````input_size = (img_size, img_size, 3)
model_name == "xception":
baseModel = Xception(
weights="imagenet",
include_top=False,
input_shape=(img_size, img_size, 3)
)
headModel = Dense(512, activation="relu", kernel_initializer="he_uniform", name="fc1")(
)
predictions = Dense(
2,
activation="softmax",
kernel_initializer="he_uniform")(
)
model = Model(inputs=baseModel.input, outputs=predictions)
model_l = Model(
inputs=baseModel.input,
outputs=model.get_layer("global_avg").output
)
for layer in baseModel.layers:
layer.trainable = False
``````

## c# – Pasar model IEnumerable y Model binding a View ASP.NET MVC

Resulta que tengo una vista donde estoy pasando un modelo que tiene una lista para mostrarla:

VIEW

``````@model IEnumerable<IHR.Models.MapaEmpleadoGeneral>

@foreach (var m in Model)
{
@m.Nombre
//etc........
}
``````

La cual esta mostrando esto:

MODELO

``````public class MapaEmpleadoGeneral
{
public string Cedula { get; set; }
public string Nombre { get; set; }
public string Apellidos { get; set; }
public string Descripcion_Area { get; set; }
}
``````

Me muestra todo correcto, resulta que quiero aplicar el ModelBinding en un form, por que la misma vista quiero aparte de mostrar tambien guardar unos datos, asi que estoy haciendo algo asi:

``````public class Empleado
{
//(Required)
//public Guid Id { get; set; }

//(Required)
//public DateTime Creado { get; set; }

//(Required(ErrorMessage = "Nombre es requerido"))
//(StringLength(50, ErrorMessage = "Logitud máxima 50"))

(Required(ErrorMessage = "Requerido"))
(StringLength(50, ErrorMessage = "Logitud máxima 50"))
public string Cedula { get; set; }

(Required(ErrorMessage = "Requerido"))
(StringLength(50, ErrorMessage = "Logitud máxima 50"))
public string Nombre { get; set; }

(Required(ErrorMessage = "Requerido"))
(StringLength(70, ErrorMessage = "Logitud máxima 50"))
public string Apellidos { get; set; }

(StringLength(50, ErrorMessage = "Logitud máxima 50"))
public string Telefono { get; set; }

(StringLength(50, ErrorMessage = "Logitud máxima 50"))
public string Email { get; set; }

public DateTime? Cumple { get; set; }

(StringLength(250, ErrorMessage = "Logitud máxima 250"))
public string Direccion { get; set; }

public int? Genero { get; set; }

public int? Area { get; set; }

public int? Jefe { get; set; }

}
``````

y quiero utilizar algo asi en la vista:

``````@Html.TextBoxFor(x => x.Nombre,
new { @class = "form-control", placeholder = "Nombre", autofocus = "autofocus" })
@Html.ValidationMessageFor(x => x.Nombre, null, new { @class = "text-danger" })
``````

pero no puedo pasar ambos, o segun el ejemplo que sigo ambos no se jalan igual, por ejemplo, para mostrar la lista de datos debo pasar el de la lista asi:

``````@model IEnumerable<IHR.Models.MapaEmpleadoGeneral>
``````

si quiero pasar el Model Binding debo pasarlo asi:

``````@model Empleados
``````

Que esta mal en mi codigo y como puedo hacer que ambos pasen? Gracias.

## Facebook M2M-100 Language Translation Model Now Open Sourced

Facebook has a new AI multilingual, 100 language translation model, M2M-100, which it releasing to open source.

## database design – Cardinality in a Logical Model by number of rows Vs natural relationship between entities

How should one determine Cardinality in a Logical Model ?

Should it be based on how the rows of an entity relate to another entity or should we consider the natural relationship between the entities i.e. conceptual relationship between the entities ?

Example: If I have an entity Course and an entity Course Type, what would be the cardinality ? Each course can have only one course type. For example, Bachelor of Arts is a course of course type Bachelors and Master of Science is of course type Masters

If I have Course Type as part of Course entity, then Course Type would only contain list of valid course types and it would be “many-to-one” (non-identifying) as there are many courses which will could 1 course type.

On the other hand if I model it in such a way that Course Type entity has Course ID (foreign Key) and Course Type , then the relationships between Course and Course Type is “one-to-one” (identifying).

Basically what I am trying to understand is, which one the following is right ?

each course has one course type OR many courses have one course type

How should one make this decision ? Are there any guidelines ?

P.S. : I am a beginner and using Oracle Data Modeler

## What do MacBook Pro 2020 model codes mean?

There’s no 2020 or 2021 model of the 16″ MacBook Pro currently. The 16″ MacBook Pro only exists as the Late 2019 model – there are no others.

The codes you have refer to various build-to-order variants. For example you can buy the 16″ model with 16 GB RAM, 32 GB or 64 GB RAM, there’s 3 different CPU models, 3 GPU variants, 5 SSD sizes, and so on.