c# – In the absence of code-contracts, what techniques exist to represent state invariants (e.g. “Customer with Orders loaded” with Entity Framework)?


There is a significant difference between an entity and a viewmodel. You’ve already pointed one out: entities have no inherent requirements of linked entities to exist/be loaded, but in this case your viewmodel does.
Since your viewmodel is the one who causes this requirement to exist, putting it in the viewmodel is precisely the place it should be enshrined.

but this introduces a lot of time wasting by essentially copying the data’s structural definition from the Entity type to the View-Model type

This is the age-old mantra of bad practice justifications. I want to cut this corner because I it’s a waste of time.

Not only should you take the time and effort to separately declare the structure of an entity and a viewmodel, regardless of any similarities they may share; but you also seem to have skipped one or two extra layers of indirection, i.e. the database DTO and business DTO.

This is where we get to differing opinions on where the bar is set. Some advocate that you always need all layers. Some advocate a more contextual approach. But I think you’ll get a near unanimous agreement that entities and viewmodels are the absolute barebones requirements for indirection. I would personally suggest having at least one additional layer of indirection in there, but that’s a contextual inference on my part about the scope and complexity of your application.

if the View Model class simply embeds Entity Types (which is fine when the View Model is not being used in a <form>!)

I have no idea where you got this idea, I have never heard of this argument before, and I disagree with it wholly.

Whether or not your data ends up in a form is completely irrelevant. Any data you send to a browser gets sent as HTML (since you’re talking about <form>) and inherently loses all connection to the entity that was the source of the data.

If the user ends up making a second request, this time containing some form data that just happens to be the same as the entity you used for the first request, that’s a completely separate request, with its own scope, and no bearing on the entity from the first event.

Note that a slightly different argument applies to non-HTML formats, e.g. a WPF app; but it’s the same conclusion in the end. Here, at the end of a rendering a view the entity does not necessarily descope yet (because it can and most likely will be kept in memory). However, the only way in which your rendered view impacts the entity is if you set up a binding. And it makes no sense to set up the binding for the content of an immutable object. If it’s immutable, then you wouldn’t be able to reflect any changes made to the data anyway.

which doesn’t “scale” when an application could have hundreds of different views all with similar requirements

We’ve now hit on the second mantra of bad practice justification. I could decide to not cut this corner, but there are many corners ahead, and not cutting any corner is a waste of time.

Every class exists because it has its own defined purpose. Different purpose? Different class. Same purpose? Same class.

Note the difference between a class’ purpose and its structure. Two classes may exist with the exact same class structure, but each serving a different purpose (DTOs are a common example here). Overzealous refactoring may lead you to condense these two classes together as their structure is the same, but that is a bad practice mistake. Each class serves its own purpose and therefore each class has its own reason to exist.

The size of an application is not justification for cutting corners. There is not a single good practice rule that has a “unless you have a lot of classes” kind of exception to it.

Just imagine if you find out that the contractor building your house skipped parts of the building plan “because they have a lot of houses to build”. The building plan is to be followed, regardless of how many building plans exist.
“I had to do many” is just not a valid argument. But often, we only care about that when we personally suffer from the corner-cutting, rather than when we’re the one doing it for our own benefit (i.e. less work).


And this immutable View Model for a page

class CustomerOrderPageViewModel : IPageViewModel
    public Customer CustomerSubject { get; }

If Customer is mutable, then given its class definition, CustomerOrderPageViewModel is also mutable, since you can do things like this:

var model = new CustomerOrderPageViewModel(new Customer);

model.CustomerSubject.Name = "I can totally change this";

Immutability can only be built on immutability. An interesting discussion appears when you consider if Customer had not been publically accessible from the viewmodel, e.g.:

class CustomerOrderPageViewModel : IPageViewModel
    private readonly Customer customer;
    public Customer CustomerName => this.customer.Name;

Is this immutable? I’ve heard argument either way. You cannot alter a CustomerOrderPageViewModel instance. However, it’s still possible to indirectly alter the data contained in this CustomerOrderPageViewModel instance:

var customer = new Customer();
var model = new CustomerOrderPageViewModel(customer);

var modelName_1 = model.CustomerName;

customer.Name = "Different";

var modelName_2 = model.CustomerName;

If the same property of the same instance can yield different values, then the object is by definition mutable.

This answer explores the issue better than I can, but the gist of it is that the only way to have an immutable class that is based on a mutable reference type (i.e. the entity) is to (a) obviously not expose any mutable types as properties and (b) copy all the needed data in the constructor, so that any future changes made to the instance of the mutable reference type no longer cause changes to the content of your immutable instance.

Note that when you do actually implement the indirection described above, and your viewmodels and entities are separate, then you can in fact achieve immutability easily here. I just wanted to point out that what you call immutability is not in fact immutability, because you are liable to repeat that mistake even if you were to add a layer of indirection.

sql server – How to represent rows as column from details table?

I work on SQL server 2012 I have issue i can’t represent rows as columns .

i need to represent code type from details table to display as column with

values of count parts from details table .

join between master and details by plid

every plid have group of code type so instead of represent code type as rows

i will represent it as columns

columns will have header as code type and content column will be count parts

so How to do that please ?

create table #master
 zplid int,
 zplidname  nvarchar(50)
 insert into #master(zplid,zplidname) 

 create table #details
 zplid int,
 CodeType  int,
 CountParts int
 insert into #details(zplid,CodeType,CountParts) 

Result :

join between master and details

camera controls – What does the Custom White-Balance *icon* represent?

I already know what White Balance is (at least enough to get by!) I already know what Custom White Balance is.

All of the pre-configured White Balance options on the Canon DSLRs have meaningful icons – pictures of the sun, clouds, tungsten and fluoro lights, etc.

But the Custom White Balance icon is a mystery to me. It is a round-corners black rectangle upon two white triangles. (There’s a picture here from this site.). Update, here is the pic:

alt text

My idle thought after some late-night experimentation with white-balance is: What are these shapes supposed to represent?

(Update: Originally I thought this was just Canon, but answers below indicate other brands use it too, including Pentax and Olympus. I checked quickly before originally posting, and Nikon have a different name for it (Preset), and no icon in the manual I checked.)

java – What should I use to graphically represent an object’s position on a fixed path using python(preferred)?

Consider 2 roads merging into one(This map is supposed to remain fixed). The program will not generate this map. The program will read this map and plot positions on it on its own.


The python program will control the position of the object. The program is supposed to “highlight” or “fill” a box when the object is at that position, and then empty it as the object changes the position. For example, if the object goes from c10 to c1, and then from b10 to b1, the boxes should be filled and vacated as the position changes.

I don’t need the code and stuff. I just need something to graphically represent these “boxes” on, that can be controlled by the program. It’s not “text” so I can’t just print it on a cmd window. I need something that is a little interactive.

I tried looking for python controlled electric circuit simulators, so that I can represent the positions using light bulbs as “boxes” to switch on and off. Couldn’t find what I’m looking for. And I came across some game engines to represent it on, but I don’t know if they are the right choice. I’m also not looking for good graphics, the representation needs to be as minimal as possible with some solid colors.

(I Prefer Python, it’s better for me if I can make it work with Python, but I can work with Java and C too)

How to represent hierarchy in a use case diagram

I need to finish a task in my homework. I need to include a use case diagram. I have the following situation I have a master, admin, manager, seller and attendant users. It is like this, master is the root user. It is the only user on the system if none was created. The master user can create an admin. The admin is like the master user. The manager can see statistics. The seller can change an order status. The attendant can view the list of products on the system.

master can view statistics, change order status, view product list
admin can view statistics, change order status, view product list
manager can view statistics, change order status, view product list
seller can change order status, view product list
attendant can view product list

As you can see the set of rights that user can perform are getting filtered as the hierarchy goes down.
How can I represent this in a use case diagram. Don’t think I am lazy. I searched online and I was more confused than before.

lie groups – If $SO(3,mathbb C)$ is isomorphic to $PGL(2,mathbb C)$, what objects do vectors in $mathbb C^3$ represent in the context of Möbius geometry?

I hope this question isn’t too basic or ambiguous for this site.

The following is an explicit isomorphism from $PGL(2,mathbb C)$ to $SO(3,mathbb C)$:

$$left(begin{matrix}p & q\r & send{matrix}right) mapsto left(begin{matrix}p s + q r & i p r + i q s & – p r + q s\- i p q – i r s & frac{p^{2}}{2} + frac{q^{2}}{2} + frac{r^{2}}{2} + frac{s^{2}}{2} & frac{i p^{2}}{2} – frac{i q^{2}}{2} + frac{i r^{2}}{2} – frac{i s^{2}}{2}\- p q + r s & – frac{i p^{2}}{2} – frac{i q^{2}}{2} + frac{i r^{2}}{2} + frac{i s^{2}}{2} & frac{p^{2}}{2} – frac{q^{2}}{2} – frac{r^{2}}{2} + frac{s^{2}}{2}end{matrix}right)$$
where $i^2 = -1$.

Given that this isomorphism exists, I’m wondering whether points in $mathbb C^3$ stand for geometrically meaningful objects in the Möbius plane or Riemann sphere.

finite state machine – oval of FSM diagram represent what?

I am reading a document of varnish, and I get the important VCL state image:


we know we often use UML as standard to draw state machine.

but the svg image not, is it follow another standard? or not?

I can understand the start/end diagram (hexagon), state diagram(two rectangle), judgement condition(rhombus) ,

but I don’t understand the oval represent what, please tell me.

cthulhu dark – Can you use the occupational expertise die to represent non-occupation-related experience?

In Cthulhu Dark, when you roll to find out how well you do, you roll:

  • One die if the task is within human capabilities.
  • One die if it’s within your occupational expertise.
  • Your Insanity die, if you will risk your sanity to succeed.

In a game I am currently running, the characters are trying to do something that doesn’t exactly fall under any of their occupational expertises (sneaking into the third floor of a house from outside on the ground floor). The character that is doing the sneaking is a con-man specializing in taxidermy, which doesn’t specifically suggest “breaking and entering”, but someone suggested that he did it in the past.

I allowed him to use the occupational expertise die, since it seemed like it would work to represent having prior experience with it, but I’m curious whether I’m correct in using it to represent prior experience that wasn’t directly connected with the character’s occupation.

Can you use the occupational expertise die to represent prior, non-occupation-related, experience when rolling to see how well you do?

color management – 6500k calibrated monittor – what are the RGB values to represent a given monochromatic radiation of known wavelength?

Say I’ve calibrated a monitor to the standard 6500k 2.2 gamma, and the color space is sRGB.

On this monitor, I would like to have a reasonably accurate representation of a monochromatic radiation (like a laser) of known wavelength.

The RGB pixel values should be deduced unambiguously from this data. How do I do it?

(I understand there is no way to truly show monochromatic stuff on a monitor – I’m just asking for the best approximation of the hue)

usability – What is the best way to represent editable options that change the viewport?

I am trying to figure out how what the best approach UI/UX wise is for the behavior I desire. I have a dashboard with a sidebar on the left, and all of the behavior I am describing happens on one page, so the sidebar is essentially static for my problem.

I’ve made a very rough draft of what the app will look like, essentially the dashboard will have a way to move between different galleries. The current selected gallery is represented by the grid at the bottom with the big “+”. The way to move between views will be in the area represented by “???”. Behavior-wise, what I want is very similar to tabs in that I would like the user to be able to select an option and the option that is selected will change the gallery that is being displayed. However, I would like the various options to be editable in that I would like them to be able to be renamed and deleted, with potential support for reordering.

What would be the best approach for this?

enter image description here