Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: Implementing IDictionary results in not mapped [664]

$
0
0
implementing IDictionary results in not mapped.



example attached :

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace dict.Models
{
public class DictItem
{
[Key]
public int Key { get; set; }
public string Value { get; set; }
}
public class DictList
{
public int DictListId { get; set; }
public List<DictItem> MyFakeDict { get; set; }
}
public class Dict : IDictionary<int, string>
{
public int DictId { get; set; }
public List<DictItem> MyDict { get; set; }

public void Add(int key, string value)
{
if (!ContainsKey(key))
MyDict.Add(new DictItem { Key = key, Value = value });
else
throw new System.ArgumentException("An item with the same key has already been added.");
}

public bool ContainsKey(int key)
{
foreach (int Key in Keys)
if (Key == key)
return true;

return false;
}

public ICollection<int> Keys
{
get
{
List<int> languagelist = new List<int>();
foreach (DictItem item in MyDict)
languagelist.Add(item.Key);

return languagelist;
}
}

public bool Remove(int key)
{
foreach (DictItem item in MyDict)
{
if (item.Key == key)
return MyDict.Remove(item);
}
return false;
}

public bool TryGetValue(int key, out string value)
{
foreach (DictItem item in MyDict)
{
if (item.Key == key)
{
value = item.Value;
return true;
}
}
value = default(string);
return false;
}

public ICollection<string> Values
{
get
{
ICollection<string> itemlist = new List<string>();
foreach (DictItem item in MyDict)
itemlist.Add(item.Value);

return itemlist;
}
}

public string this[int key]
{
get
{
foreach (DictItem item in MyDict)
{
if (item.Key == key)
return item.Value;
}
return default(string);
}
set
{
if (!ContainsKey(key))
Add(key, value);
}
}

public void Add(KeyValuePair<int, string> item)
{
Add(item.Key, item.Value);
}

public void Clear()
{
MyDict.Clear();
}

public bool Contains(KeyValuePair<int, string> item)
{
string founditem;
if (TryGetValue(item.Key, out founditem))
return founditem.Equals(item.Value);

return false;
}

public void CopyTo(KeyValuePair<int, string>[] array, int arrayIndex)
{
if (array == null)
throw new System.ArgumentNullException("array is null.");
if (arrayIndex < 0)
throw new System.ArgumentOutOfRangeException("index is less than zero.");
if (array.Length - arrayIndex < this.Count)
throw new System.ArgumentException("The number of elements in the source System.Collections.Generic.Dictionary<TKey,TValue>.KeyCollection is greater than the available space from index to the end of the destination array.");
for (int i = 0; i < MyDict.Count; i++)
{
array[i + arrayIndex] = new KeyValuePair<int, string>(MyDict[i].Key, MyDict[i].Value);
}
}

public int Count
{
get { return MyDict.Count; }
}

public bool IsReadOnly
{
get { return false; }
}

public bool Remove(KeyValuePair<int, string> item)
{
return Remove(item.Key);
}

public IEnumerator<KeyValuePair<int, string>> GetEnumerator()
{
throw new NotImplementedException();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
public class MyClass
{
public int MyClassId { get; set; }
public DictList MyDictList { get; set; }
public Dict MyDict { get; set; }
}
}

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>