Let $X$ be a proper one dimensional scheme over $k$ (so over a Noetherian ring). Consider a finite discrete closed subscheme $D \subset X$. By definition $D = \{d_1, d_2, ..., d_n \}$ and for the induced structure sheaf of $D$ we obviously have $H^0(D, \mathcal{O}_D) = \oplus _{d_i} \mathcal{O}_{D, d_i}$.
My questions are:
Why does $\dim_k H^0(D, \mathcal{O}_D) = \dim_k \oplus _{d_i} \mathcal{O}_{D, d_i} = \sum _{d_i} \operatorname{length} \mathcal{O}_{D, d_i}$ hold? Expecially over which ring $R$ we interpret each $\mathcal{O}_{D, d_i}$ as a $R$-module by considering the module length? Over $R =k$?
Why $X$ must be reduced if we want that $\dim_k \oplus _{d_i} \mathcal{O}_{D, d_i} = \sum _{d_i} [k(d_i): k]$ holds? Can't we always lift the dimension $[k(d_i): k]$ of $k(d_i)$ as $k$ vector space by Nakayama to the the $k$-dimension of the local ring $\mathcal{O}_{D, d_i}$?
My ideas to 1.: That's clear that $\dim_k \oplus _{d_i} \mathcal{O}_{D, d_i} = \sum _{d_i} \dim_k \mathcal{O}_{D, d_i} $ and furthermore for every $k$ vector space $V$ we have $\dim_k V = \operatorname{length}_k V$ with $V$ as $k$ module.
So I can reduce the claim to the proof that $\operatorname{length}_k \mathcal{O}_{X, d_i} =\operatorname{length}_{\mathcal{O}_{D, d_i}} \mathcal{O}_{D, d_i}$ must hold. Why?
Remark: Using A.Rod's hint I mean $\operatorname{length}\mathcal{O}_{D, d_i} = \operatorname{length}_{\mathcal{O}_{D, d_i}} \mathcal{O}_{D, d_i}$ so considering $\mathcal{O}_{D, d_i}$ as a $\mathcal{O}_{D, d_i}$-module.