I have the following code, which I'm using to get the values from a forms collection
List<FlowSettings> lst = new List<FlowSettings>();
string[] IsVisible = fc["IsVisible"].Split(',');
string[] Editable = fc["Editable"].Split(',');
string[] Revisable = fc["Revisable"].Split(',');
string[] tbl = fc["tblId"].Split(',');
The above arrays are just for me to ensure that I'm getting the data as expected. My problem is, I can loop over the forms collection, but cannot get the values out and add to my list.
foreach (var _key in fc.Keys)
{
var _value = fc[_key.ToString()];
//lst.Add(new FlowSettings { TblId = Convert.ToInt32(_value[0]), ChxIsVisible =
Convert.ToBoolean(_value[1]),
ChxEditable = true,
ChxRevisable = true
});
}
The values in IsVisible etc have 10 rows which are bool and tbl is an int
Can anyone let me know what I'm missing
--------------Extra code-------------------
public ActionResult FlowItems(FormCollection fc)
lst is in the foreach loop
FormCollection does not implement the IDictionary(TKey,TValue) interface, so you need to loop through and get the values.
Data
public class FlowSettings
{
public bool IsVisible { get; set; }
public bool Editable { get; set; }
public bool Revisable { get; set; }
public int TblId { get; set; }
}
private bool ParseBool(string value)
{
return Convert.ToBoolean(EmptyToFalse(value));
}
private int ParseInt(string value)
{
return Convert.ToInt32(EmptyToInvalid(value));
}
private string EmptyToFalse(string value)
{
return string.IsNullOrWhiteSpace(value) ? bool.FalseString : value;
}
private string EmptyToInvalid(string value)
{
return string.IsNullOrWhiteSpace(value) ? "-1" : value;
}
Create
var col1 = new NameValueCollection
{
{ "IsVisible", "True" },
{ "Editable", "True" },
{ "Revisable", "True" },
{ "tblId", "100" },
};
var col2 = new NameValueCollection
{
{ "IsVisible", "True" },
{ "Editable", "" },
{ "Revisable", "True" },
{ "tblId", "101" },
};
var formCollection = new FormCollection
{
col1,
col2
};
var length =
formCollection
.Cast<string>()
.Select(entry => formCollection.GetValues(entry).Length)
.Max();
Loop
var items = new List<FlowSettings>();
for(var i = 0; i < length; i++)
{
var flowSettings = new FlowSettings
{
IsVisible = ParseBool(formCollection.GetValues("IsVisible")[i]),
Editable = ParseBool(formCollection.GetValues("Editable")[i]),
Revisable = ParseBool(formCollection.GetValues("Revisable")[i]),
TblId = ParseInt(formCollection.GetValues("tblId")[i]),
};
items.Add(flowSettings);
}
There is a caveat to this approach. If there is data missing from col1 or col2. e.g.
var col3 = new NameValueCollection
{
{ "IsVisible", "True" },
{ "Editable", "" },
// { "Revisable", "True" }, Missing this entry
{ "tblId", "102" },
};
Then the loop with be out of bounds.
The problem might be that the collection contains values that are comma-delimited (I'm assuming that because of the Split() at the beginning your question) but in the for loop you are using the value directly without splitting on commas. So I guess it would be trying to create a bool out of the 2nd character (index of 1) of the value.
Try this instead:
foreach (var _key in fc.Keys)
{
var _value = fc[_key.ToString()];
string[] tokenized = _value.Split(',');
bool b = Convert.ToBoolean(tokenized[1]);
}
Related
I have two lists. I want to compare two lists and change the Selected bool property false to true from firstInstance if the selectedInstance list items should have in the firstInstance list. I have tried below code using IEnumerator but not getting as expected.
I am expecting the output:
List<Data> firstInstance = new List<Data>
{
new Data { AccountNo = 1001,AccountName="AccountName1",BranchName="BranchName1", Selected = false },
new Data { AccountNo = 1101,AccountName="AccountName2",BranchName="BranchName2", Selected = true},
new Data { AccountNo = 1051,AccountName="AccountName3",BranchName="BranchName3", Selected = false },
new Data { AccountNo = 1991,AccountName="AccountName4",BranchName="BranchName4", Selected = true},
new Data { AccountNo = 1234,AccountName="AccountName5",BranchName="BranchName5", Selected = false },
};
I have tried below code:-
static class Program
{
static void Main(string[] args)
{
List<Data> firstInstance = new List<Data>
{
new Data { AccountNo = 1001,AccountName="AccountName1",BranchName="BranchName1", Selected = false },
new Data { AccountNo = 1101,AccountName="AccountName2",BranchName="BranchName2", Selected = false },
new Data { AccountNo = 1051,AccountName="AccountName3",BranchName="BranchName3", Selected = false },
new Data { AccountNo = 1991,AccountName="AccountName4",BranchName="BranchName4", Selected = false },
new Data { AccountNo = 1234,AccountName="AccountName5",BranchName="BranchName5", Selected = false },
};
List<Data> selectedInstance = new List<Data>
{
new Data { AccountNo = 1991,AccountName="AccountName4",BranchName="BranchName4", Selected = true },
new Data { AccountNo = 1101,AccountName="AccountName2",BranchName="BranchName2", Selected = true }
};
firstInstance.CheckActive(selectedInstance);
}
static void CheckActive(this List<Data> firstInstance, List<Data> selectedInstance)
{
using (IEnumerator<Data> firstEnumerator = firstInstance.GetEnumerator(), secondEnumerator = selectedInstance.GetEnumerator())
{
while (true)
{
if (!firstEnumerator.MoveNext() || !secondEnumerator.MoveNext()) break;
if (firstEnumerator.Current.AccountNo == secondEnumerator.Current.AccountNo) firstEnumerator.Current.Selected = true;
}
}
}
}
class Data
{
public int AccountNo { get; set; }
public string AccountName { get; set; }
public string BranchName { get; set; }
public bool Selected { get; set; }
}
So you want to set the Selected property to true for all items in the first list which match with the second list, that only contains selected items?
Then this Join approach is efficient and works:
var query = from activeData in selectedInstance
join allData in firstInstance
on activeData.AccountNo equals allData.AccountNo
select allData;
foreach(Data selectedData in query)
{
selectedData.Selected = true;
}
Your approach does not work because you stop enumeration if one list is at the end. But you have to enumerate the other list(which contains all data) until end. You also have to compare each item with all other items, not just at the same index.
Not sure why you'd need both enumerators iterating together. The collections' size doesn't seem to match.
I would do something much simpler:
var selectedAccounts = selectedInstance.Select(d => d.AccountNo).ToList();
foreach (var selected in firstInstance.Where(d => selectedAccounts.Contains(d.AccountNo)))
{
selected.Selected = true;
}
This is assuming you are not trying to account for performance and big data structures.
edit this line of code:
// firstInstance.CheckActive(selectedInstance);
CheckActive(firstInstance,selectedInstance)
and use this function...
public static void CheckActive(List<Data> firstInstance, List<Data> selectedInstance)
{
var result = firstInstance.Where(y => selectedInstance.Any(z => z.AccountNo == y.AccountNo)).ToList();
foreach (var _item in firstInstance)
{
if (result.Any(z => z.AccountNo == _item.AccountNo))
{
_item.Selected = true;
}
}
}
One way would be to find all the instances in firstInstance where the AccountNo of the item matches the AccountNo of Any of the items in the selectedInstance list, and set the Selected property of those items to true in a foreach loop:
foreach (var item in firstInstance.Where(first =>
selectedInstance.Any(selected => selected.AccountNo == first.AccountNo)))
{
item.Selected = true;
}
I have a problem in writing my query with C#.
Hee is my data model:
public class SpamEntity:MongoEntity
{
public IList<MessageData> MessageData { get; set; }
}
public class MessageData
{
public IList<string> EmbeddedLinks { get; set; }
}
here I have a list of links like :
var myLinks = {"a.com", "b.com", "c.com"}
I want to filter those documents that their list of EmbededLinks is not empty (count or length is zero) and exactly the same as myLinks.
I am halfway and I do not know what to do in continue.
my filter is something like:
var filter =
Builders<SpamEntity>.Filter.ElemMatch(s => s.MessageData,
s => s.EmbeddedLinks != null && s.EmbededLinks == ???);
I think the below should not be correct.
s.EmbededLinks == myLinks
and also I can not use count:
s.EmbeddedLinks.count => It does not work
Could anyone help me with that?
Not sure about mongodb specific filters..
below is a linq variant (assumption ordering doesnt matter!)
var filtered =
spamEntities.MessageData.Where(
m =>
m.EmbeddedLinks.Any() && //ensure EmbeddedLinks has some values
m.EmbeddedLinks.Count() == myLinks.Count() && //and that count is same as our reference collection
m.EmbeddedLinks.Intersect(myLinks).Count() == myLinks.Count()); //ensure elements match
working code
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace SOProject
{
public class SpamEntity
{
public IList<MessageData> MessageData { get; set; }
}
public class MessageData
{
public IList<string> EmbeddedLinks { get; set; }
}
public class SO
{
[Fact]
public void Q_63081601()
{
var myLinks = new List<string> { "a.com", "b.com", "c.com" };
var size = myLinks.Count();
var data2 = new List<string>(myLinks);
var data3 = new List<string>(myLinks) { "sdsadsad.com" };
var data4 = new List<string> { "c.com", "b.com", "a.com" };
var spamEntities = new SpamEntity()
{
MessageData = new List<MessageData>
{
new MessageData()
{
EmbeddedLinks = new List<string> { "", "aaaa.com", "bbb.com" }
},
new MessageData()
{
EmbeddedLinks = data2
},
new MessageData
{
EmbeddedLinks = Enumerable.Empty<string>().ToList()
},
new MessageData()
{
EmbeddedLinks = data2
},
new MessageData()
{
EmbeddedLinks = data3
},
new MessageData()
{
EmbeddedLinks = data4
}
}
};
var filtered =
spamEntities.MessageData.Where(
m =>
m.EmbeddedLinks.Any() && //ensure EmbeddedLinks has some values
m.EmbeddedLinks.Count() == myLinks.Count() && //and that count is same as our reference collection
m.EmbeddedLinks.Intersect(myLinks).Count() == myLinks.Count()); //ensure elements match
Assert.True(filtered.Any());
Assert.Equal(3, filtered.Count());
}
}
}
I am consuming an API that returns JSON that looks like this:
{
"lookup_table_data": [
[
{
"key": "id",
"value": 0
},
{
"key" : "label",
"value" : "something"
}
],
[
{
"key": "id",
"value": 1
},
{
"key" : "label",
"value" : "something_else"
}
]
]
}
I made a class that I deserialize the json object into that looks like this:
public class LookupResponseModel
{
public Lookup_Table_Data[][] Lookup_table_data { get; set; }
public class Lookup_Table_Data
{
public string Key { get; set; }
public object Value { get; set; }
}
}
Now imagine that the JSON response has over 1,000 records instead of the 2 that I gave in my example.
I am wanting to search through my model and be able to find where the value of the key "id" is equal to 1 - because I want to use the label key value of "something_else".
How would I be able to grab the label "something_else" with an id of 1 with this model?
var lookup = model.lookupTableData.Select(data => new { key = (long)data.First(kvp => kvp.Key == "id").Value, value = (string)data.First(kvp => kvp.Key == "label").Value).ToDictionary(kvp => kvp.key, kvp => kvp.value)
var displayText = lookup[1]; // "something_else"
My attempt from a phone, might not be 100% correct syntax.
I would suggest an approach like this:
public class LookupResponseModel
{
public Lookup_Table_Data[][] Lookup_table_data { get; set; }
public class Lookup_Table_Data
{
public string Key { get; set; }
public object Value { get; set; }
}
}
// This will help compare the values and convert if necessary
// This part was missing from my original answer and made it not work
bool ObjectCompare(object a, object b)
{
if (object.Equals(a, b))
{
return true;
}
else
{
var altB = Convert.ChangeType(b, Type.GetTypeCode(a.GetType()));
return object.Equals(a, altB);
}
}
// This will break the result up into an Array of Dictionaries
// that are easier to work with
Dictionary<string, object>[] MakeTables(LookupResponseModel lrm)
{
return lrm.Lookup_table_data.Select( entry => entry.ToDictionary( e => e.Key, e => e.Value ) ).ToArray();
}
// This will help you find the dictionary that has the values you want
Dictionary<string, object> FindTable( Dictionary<string, object>[] tables, string key, object value )
{
return tables.Where( dict => dict.TryGetValue(key, out object val) && ObjectCompare(value, val) ).FirstOrDefault();
}
// Here is how you might use them together
string GetLabel()
{
var lrm = JsonConvert.DeserializeObject<LookupResponseModel>(json);
var lookup = MakeTables(lrm);
var table = FindTable( lookup, "id", 1 );
return table["label"].ToString(); // Returns "something_else"
}
Data :
LookupResponseModel model = new LookupResponseModel();
model.Lookup_table_data = new LookupResponseModel.Lookup_Table_Data[][]
{
new LookupResponseModel.Lookup_Table_Data[]
{
new LookupResponseModel.Lookup_Table_Data(){Key = "id", Value = "0"},
new LookupResponseModel.Lookup_Table_Data(){Key = "label", Value = "hello"},
new LookupResponseModel.Lookup_Table_Data(){Key = "textbox", Value = "bye"}
},
new LookupResponseModel.Lookup_Table_Data[]
{
new LookupResponseModel.Lookup_Table_Data(){Key = "id", Value = "1"},
new LookupResponseModel.Lookup_Table_Data(){Key = "label", Value = "banana"},
new LookupResponseModel.Lookup_Table_Data(){Key = "textbox", Value = "potatoe"}
},
new LookupResponseModel.Lookup_Table_Data[]
{
new LookupResponseModel.Lookup_Table_Data(){Key = "id", Value = "2"},
new LookupResponseModel.Lookup_Table_Data(){Key = "label", Value = "cat"},
new LookupResponseModel.Lookup_Table_Data(){Key = "textbox", Value = "bydog"}
}
};
This query gives us second set (all 3 Lookup_Table_Data where key is ID and value is 1) It still [][] and it can contain more than one result :
var _result = model.Lookup_table_data.Where(x => x.Any(y => y.Key == "id" && y.Value.Equals("1")));
And this one gives you exactly value of "label" key from previous set (Key = "label", Value = "banana") :
var _exactlyLabel = _result.Select(x => x.Where(y => y.Key == "label"));
Or you can make _result.SelectMany(... for [] not for [][]
The simple answer is, you say something like this
public class LookupResponseModel
{
public LookupTableData[][] lookupTableData { get; set; }
public class LookupTableData
{
public string Key { get; set; }
public object Value { get; set; }
}
public LookupTableData[] FindById( int id )
{
if (this.lookupTableData == null) throw new InvalidOperationException();
foreach ( LookupTableData[] entry in lookupTableData )
{
if (entry != null)
{
foreach( LookupTableData item in entry )
{
bool isMatch = "id".Equals( item.Key ?? "", StringComparison.Ordinal )
&& item.Value is int
&& ((int)item.Value) == id
;
if ( isMatch )
{
return entry;
}
}
}
}
return null;
}
}
I am working on code which will give Cartesian product of two anonymous types. These 2 anonymous types are generated from database.
Code for 1st anonymous type:
private IEnumerable<object> GetItem()
{
return _unitOfWork.GetRepository<Item>()
.ListAll()
.Select(x => new
{
itemId = x.Id,
itemName = x.Name
})
}
Code for 2nd anonymous type:
private IEnumerable<object> GetVenue()
{
return _unitOfWork.GetRepository<Venue>()
.ListAll()
.Select(x => new
{
locationName = x.Address.City,
venueId = x.VenueId,
venueName = x.Name
})
}
I have following method to get the data and perform Cartesian product and return the data.
public object GetRestrictLookupInfo(IEnumerable<int> lookupCombinations)
{
IEnumerable<object> restrictList = new List<object>();
if (lookupCombinations.Contains(1))
{
var tempProductProfileList = GetItem();
restrictList = tempProductProfileList.AsEnumerable();
}
if (lookupCombinations.Contains(2))
{
var tempProductGroupList = GetVenue();
restrictList = (from a in restrictList.AsEnumerable()
from b in tempProductGroupList.AsEnumerable()
select new { a, b });
}
return restrictList;
}
I have controller which calls this method and return data in json format.
Controller Code
public HttpResponseMessage GetData(IEnumerable<int> lookupCombinations)
{
var lookupRestrictInfo = _sellerService.GetRestrictLookupInfo(lookupCombinations);
return Request.CreateResponse(HttpStatusCode.OK, lookupRestrictInfo);
}
Response expected is:-
[ {
"itemId": 1,
"itemName": "Music",
"locationName": "Paris",
"venueId": 99,
"venueName": "Royal Festival Hall"
} ]
Response which I receive is
[ {
"a": {
"itemId": 1,
"itemName": "Music"
},
"b": {
"locationName": "Paris",
"venueId": 99,
"venueName": "Royal Festival Hall" } }]
I am not able to get the expected JSON string.
You should start with the simplest possible code that shows your problem; your code above has a lot of complexities that may (or may not) have anything to do with your problem. Is this about manipulating anonymous types? Doing a Cartesian product with LINQ? Converting an object to JSON?
Here's one possible answer to what you might be looking for; notice that you can pass around anonymous types using generics instead of object.
namespace AnonymousTypes
{
class Program
{
static string Serialize(object o)
{
var d = (dynamic)o;
return d.ItemId.ToString() + d.ItemName + d.VenueId.ToString() + d.LocationName + d.VenueName;
}
static string GetData<T>(IEnumerable<T> result)
{
var retval = new StringBuilder();
foreach (var r in result)
retval.Append(Serialize(r));
return retval.ToString();
}
static string GetRestrictLookupInfo()
{
var restrictList = new[] { new { Id = 1, Name = "Music" }, new { Id = 2, Name = "TV" } };
var tempProductGroupList = new[] { new { LocationName = "Paris", Id = 99, Name = "Royal Festival Hall" } };
var result = from item in restrictList
from venue in tempProductGroupList
select new
{
ItemId = item.Id,
ItemName = item.Name,
LocationName = venue.LocationName,
VenueId = venue.Id,
VenueName = venue.Name
};
return GetData(result);
}
public static string GetData()
{
return GetRestrictLookupInfo();
}
static void Main(string[] args)
{
var result = GetData();
}
}
}
If that's not what you're looking for, you might start with code that doesn't use anonymous types, such as
namespace AnonymousTypes
{
sealed class Item
{
public int Id { get; set; }
public string Name { get; set; }
}
sealed class Venue
{
public string LocationName { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
sealed class ItemAndVenue
{
public int ItemId { get; set; }
public string ItemName { get; set; }
public string LocationName { get; set; }
public int VenueId { get; set; }
public string VenueName { get; set; }
}
class Program
{
static IEnumerable<Item> GetItem()
{
return new[] { new Item { Id = 1, Name = "Music" } };
}
static IEnumerable<Venue> GetVenue()
{
return new[] { new Venue { LocationName = "Paris", Id = 99, Name = "Royal Festival Hall" } };
}
static IEnumerable<ItemAndVenue> GetRestrictLookupInfo()
{
var restrictList = GetItem();
var tempProductGroupList = GetVenue();
var result = from item in restrictList
from venue in tempProductGroupList
select new ItemAndVenue
{
ItemId = item.Id,
ItemName = item.Name,
LocationName = venue.LocationName,
VenueId = venue.Id,
VenueName = venue.Name
};
return result;
}
static string GetData()
{
var v = GetRestrictLookupInfo().First();
return v.ItemId.ToString() + v.ItemName + v.VenueId.ToString() + v.LocationName + v.VenueName;
}
static void Main(string[] args)
{
var result = GetData();
}
}
}
In order to produce a single item in the output you need to create a new type, named or anonymous. Since you are using objects rather than actual types, the quickest approach is to cast them to dynamic:
var tempProductGroupList = GetVenue();
restrictList = (from a in restrictList.Cast<dynamic>()
from b in tempProductGroupList.Cast<dynamic>()
select new {
itemId = (int)a.itemId,
itemName = (string)a.itemName,
locationName = (string)b.locationName,
venueId = (int)b.venueId,
venueName = (string)b.venueName
});
This code is tightly coupled to the code producing both lists, because it assumes the knowledge of the field names of types passed into it dynamically. Any change in the structure of source data must be followed by a change in the code making combinations. In addition, it defeats run-time checking, so you need to be very careful with this code.
Try to create a simple object instead of nesting:
select new { a.itemId, a.itemName, b.locationName }
Like an option:
public object GetRestrictLookupInfo(IEnumerable<int> lookupCombinations)
{
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
if (lookupCombinations.Contains(1))
{
var tmp = _unitOfWork.GetRepository<Item>()
.ListAll()
.Select(x => new
{
itemId = x.Id,
itemName = x.Name
})
.Select(x =>
{
var dic = new Dictionary<string, object>();
dic.Add(nameof(x.itemId), x.itemId);
dic.Add(nameof(x.itemName), x.itemName);
return dic;
});
result.AddRange(tmp);
}
if (lookupCombinations.Contains(2))
{
var tmp = _unitOfWork.GetRepository<Venue>()
.ListAll()
.Select(x => new
{
locationName = x.Address.City,
venueId = x.VenueId,
venueName = x.Name
})
.Select(x =>
{
var dic = new Dictionary<string, object>();
dic.Add(nameof(x.locationName), x.locationName);
dic.Add(nameof(x.venueId), x.venueId);
dic.Add(nameof(x.venueName), x.venueName);
return dic;
});
result = result.SelectMany(r => tmp.Select(t => r.Concat(t)));
}
return result;
}
It looks like some magic. I uses dictionary instead of object. It can be make in more clear way (extract few methods), but the idea should be clear.
Then, during serialization it will be presented as you need.
I have a below class. I will get two objects List<Client> data1 and List<Client> data2. I want to compare data1 and data2 with each of the attribute value.
For example, if data1 object has the LastName=a and ClientId=1,..etc and if data2 list has the same set of data i want to push that into one more list.
Any idea, how can we achieve this using LINQ/Minimal code?
public class Client
{
public int ClientId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Email { get; set; }
}
using Intersect
List<Client> data1 = new List<Client>();
List<Client> data2 = new List<Client>();
List<Client> newlst = new List<Client>();
Client obj = new Client();
obj.ClientId = 1;
obj.LastName = "a";
obj.FirstName = "n";
obj.Email = "e";
data1.Add(obj);
data2.Add(obj);
obj = new Client();
obj.ClientId = 2;
obj.LastName = "a";
obj.FirstName = "f";
obj.Email = "e";
data1.Add(obj);
newlst = data1.Intersect(data2).ToList();
I have used IEqualityComparer which is used to compare both the collection and Intersect will give the common value.I have tested the code for few scenario. You can check for all the scenario.
Hope this code will be helpful.
namespace UnitTestProject
{
[TestClass]
public class CompareTwoGenericList
{
[TestMethod]
public void TestMethod1()
{
var coll = GetCollectionOne();
var col2 = GetCollectionTwo();
//Gives the equal value
var commonValue = coll.Intersect(col2, new DemoComparer()).ToList();
//Difference
var except=coll.Except(col2, new DemoComparer()).ToList();
}
public List<Demo> GetCollectionOne()
{
List<Demo> demoTest = new List<Demo>()
{
new Demo
{
id=1,
color="blue",
},
new Demo
{
id=2,
color="green",
},
new Demo
{
id=3,
color="red",
},
};
return demoTest;
}
public List<Demo> GetCollectionTwo()
{
List<Demo> demoTest = new List<Demo>()
{
new Demo
{
id=1,
color="blue",
},
new Demo
{
id=2,
color="green",
},
new Demo
{
id=4,
color="red",
},
};
return demoTest;
}
}
// Custom comparer for the Demo class
public class DemoComparer : IEqualityComparer<Demo>
{
// Products are equal if their color and id are equal.
public bool Equals(Demo x, Demo y)
{
//Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
//Check whether the demo properties are equal.
return x.color == y.color && x.id == y.id;
}
// If Equals() returns true for a pair of objects
// then GetHashCode() must return the same value for these objects.
public int GetHashCode(Demo demo)
{
//Check whether the object is null
if (Object.ReferenceEquals(demo, null)) return 0;
//Get hash code for the color field if it is not null.
int hashColor = demo.color == null ? 0 : demo.color.GetHashCode();
//Get hash code for the id field.
int hashId = demo.id.GetHashCode();
//Calculate the hash code for the product.
return hashColor ^ hashId;
}
}
}
Create Your new class ClientView
public class ClientView{
public int ClientId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Email { get; set; }
}
List lst = new List();
var data = from n in db.client
select new ClientView()
{
ClientId = n.ClientId ,
LastName = n.LastName ,
FirstName = n.FirstName,
};
var data1 = from n in db.client
select new ClientView()
{
ClientId = n.ClientId ,
LastName = n.LastName ,
FirstName = n.FirstName,
};
lst.AddRange(data);
lst.AddRange(data1);
List<ClientView> lst1 = new List<ClientView>();
foreach (var singlelst in lst)
{
ClientView newClient = new ClientView ();
newClient.Id = singlelst.Id;
newClient.આપેલ = singlelst.LastName;
newClient.આપેલતારીખ = singlelst.FirstName;
lst1.Add(newClient);
}
Try this:
public IEnumerable<PropertyInfo> GetVariance(Client user)
{
foreach (PropertyInfo pi in user.GetType().GetProperties()) {
object valueUser = typeof(Client).GetProperty (pi.Name).GetValue (user);
object valueThis = typeof(Client).GetProperty (pi.Name).GetValue (this);
if (valueUser != null && !valueUser.Equals(valueThis))
yield return pi;
}
}
IEnumerable<PropertyInfo> variances = data1.GetVariance (data2);
foreach (PropertyInfo pi in variances)
Console.WriteLine (pi.Name);