I have the following table in my database
Table1: tblAddressType (id, name) Table 2: tblAddressDtls (Id, AddressTypeId, Address1) I am left in the above two tables to get the list of all address types and related address details
< Pre> sq query: select t1 *, T2 * External TLADTTTTT2 on T1 from left T1 TDTTTT2 T1 on T1 IID = T2. Address ID and T.ID = 1; For the above tables, I have created POCO unit sections as follows:
[table ("tblAddressType")] address of public partial category Type {{Key] [Column (name = "id")] Public IIT {Receive; Set; } [Required] [column (name = "name")] public virtual string name {get; Set;} [Include] [Association ("AddressTipedress", "ID", "AddressType ID")) Public Virtual Icicle & lt; Address & gt; {Receive addresses; Set; }} [Table ("tblAddress", Schema name = "DBO")] Address of the public class {[column (name = "id")] Public ID {Receive; Set; } [Column (name = "adresspid")] Public Int? Type the address {receive; Set; } [Column (name = "address 1")] public string address 1 {get; Set; } [Include] [Association ("AddressTipEdress", "AddressToIPID", "ID", ICEIREGNI = true)] Public Virtual Address Address Type {Received; Set; }} And, to bring the data shown in the above sql query, I have written the following LINQ query in my service code, and this query gives me data as needed:
var qry = (from dbContext to P in AD type type in DEB context. In the address where TID == 1 is selected) at p.ID at pa.AddressTypeId in PPA Equals. In ppa.DefaultIfEmpty () t select. Eskenable (); Now, I want to type a domain service method called "GetAddressById (int addressId)", in which I should return the Address Type object with the list of address type because I list I need to bind the "AddressType" objects in the drop down box in the address / address screen
When I was filling, I wanted to add and receive the list of "AddressType" objects data, my Option To avoid data from the round trip to the server in your Silverlight Client app. Please suggest me the best way to achieve this functionality?
New: I think that in the database, And then you are using EntityFramework. GetAddressById (int addressId) {return dbContext .Address.SingleOrDefault (a => a.ID == addressId). Include ("address type"); } The line of code can now get an address that has the ID of the address ID, if no one returns the taps or returns more then it will throw the exception; Explain that when you get the address, you should load the address type and it will be appropriate to do this, it will all create the same query for the database and would like to get the result.
Old: Let's say that we want to type the address and all its addresses with DB with only one call (as you use EntityFramework), we have a method like GetAddressTypeIncludingAddresses (int id) {return _context.addressType.Include ("Addressess"); / * If you use CTT5 of the FT code then you should be able to include (and = & gt; at.Addresses) in the * /} . addressType.Id and foreach (var address in address address.Type.Addresses) {} and when you use it like I hope that I understand your understanding, then do not try again and I will edit my answer.
Comments
Post a Comment